icpc-beijing-cats and fish
来源:互联网 发布:学而知之什么意思 编辑:程序博客网 时间:2024/05/22 11:41
原题:
- 样例输入
2 1 118 3 51 3 44 5 15 4 3 2 1
- 样例输出
1 00 10 3
描述
There are many homeless cats in PKU campus. They are all happy because the students in the cat club of PKU take good care of them. Li lei is one of the members of the cat club. He loves those cats very much. Last week, he won a scholarship and he wanted to share his pleasure with cats. So he bought some really tasty fish to feed them, and watched them eating with great pleasure. At the same time, he found an interesting question:
There are m fish and n cats, and it takes ci minutes for the ith cat to eat out one fish. A cat starts to eat another fish (if it can get one) immediately after it has finished one fish. A cat never shares its fish with other cats. When there are not enough fish left, the cat which eats quicker has higher priority to get a fish than the cat which eats slower. All cats start eating at the same time. Li Lei wanted to know, after x minutes, how many fish would be left.
输入
There are no more than 20 test cases.
For each test case:
The first line contains 3 integers: above mentioned m, n and x (0 < m <= 5000, 1 <= n <= 100, 0 <= x <= 1000).
The second line contains n integers c1,c2 … cn, ci means that it takes the ith cat ci minutes to eat out a fish ( 1<= ci <= 2000).
输出
For each test case, print 2 integers p and q, meaning that there are p complete fish(whole fish) and q incomplete fish left after x minutes.
给出鱼的数量,猫的数量,时间,以及猫吃鱼的速度,求时间过后还剩下多少完整的鱼和不完整的鱼,当鱼的数目不够的时候吃的快的猫优先
输入:
2 1 1(2条鱼,1只猫,1分钟)
1(第一只猫吃鱼的速度为1条/1min)
8 3 5(8条鱼,3只猫,5分钟)
1 3 4(1min 1条 ,3min 1条,4min 1条)
输出:
1 0(吃完了一条,还剩一条没有吃)
0 1(还剩一条正在吃,所有完整的鱼为0,不完整的为1)
思路:
模拟,给每只猫发鱼。。吃完了再发一条就ok了
代码如下:
#include<cstdio>#include<cstring>#include<cstdlib>#include<stack>#include<queue>#include<utility>#include<vector>#include<cmath>#include<set>#include<map>#include<iostream>#include<algorithm>#include<sstream>using namespace std;typedef long long LL;int m, n, x;int c[110];int eat[110];int main(){ while(scanf("%d%d%d", &m, &n, &x) == 3) { for(int i=0; i<n; i++) { scanf("%d", &c[i]); //吃一条鱼要几分钟 } sort(c, c+n); //因为要优先给吃的快的猫发鱼 memset(eat, 0, sizeof(eat)); for(int i=0; i<x; i++) { for(int j=0; j<n && m>0; j++) { if(eat[j] == 0) //如果吃完了鱼 { eat[j] = c[j]; //给每只没鱼猫发鱼 m--; } } for(int j=0; j<n; j++) { eat[j]--; //过去了一分钟 } } int inc = 0; for(int i=0; i<n; i++) { if(eat[i]>0 && eat[i]<c[i]) inc++; } printf("%d %d\n", m, inc); } return 0;}
- icpc-beijing-cats and fish
- 2017Beijing icpc E Cats and Fish HihoCoder
- Cats and Fish 2017ACM-ICPC北京赛区/hihoCoder 1631
- #1631 : Cats and Fish
- Cats and Fish HihoCoder
- Cats and Fish(模拟)
- hihocoder 1631 Cats and Fish
- ACM-ICPC北京赛区2017网络同步赛 题目5 : Cats and Fish【模拟】
- Hihocoder #1631 : Cats and Fish 模拟
- 2017icpc-beijing-j(pangu and stone)
- [hihocoder1392]ACM/ICPC Beijing
- rain cats and dogs
- fish and water
- Codeforces547D Mike and Fish
- 2014 ACM-ICPC Beijing Invitational Programming Contest
- 2015 ACM/ICPC Asia Regional Beijing Online
- Purifying Machine, ACM/ICPC Beijing 2005, UVa1663
- 2017 ICPC BeiJing Regional Hihocoder 1629 Graph
- 图论第二次课
- 01-商城购物车练习
- 绘图和可视化
- 【数据结构】可持久化线段树&Trie总结
- 结构体初始化
- icpc-beijing-cats and fish
- Spring任务调度Scheduling Tasks
- spark学习-35-Spark的Map任务输出跟踪器MapOutputTracker
- C++多任务编程简明教程 (1)
- SpringMVC中@Controller和@RequestMapping用法和其他常用注解
- Algorithm-week11
- SparkStreaming中DStream的概念
- ”复杂”的栈帧
- 产品经理,你的「核心竞争力」是?