ACM-ICPC北京赛区2017网络同步赛 题目5 : Cats and Fish【模拟】
来源:互联网 发布:网页服务器软件 编辑:程序博客网 时间:2024/05/18 02:57
题目5 : Cats and Fish
时间限制:1000ms
单点时限:1000ms
内存限制:256MB
描述
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
1
8 3 5
1 3 4
4 5 1
5 4 3 2 1
样例输出
1 0
0 1
0 3
题意: 给你m个鱼,n只猫,然后x分钟,再给出每只猫吃一条鱼所用的时间,当有一条鱼时,吃鱼速度快的抢到鱼的概率大于吃鱼慢的(简单来说就是谁吃的快是谁的),让你求x分钟后还剩多少条完整的鱼,和不完整的鱼
分析: 开始看到这个题还以为是贪心,然后就wa了,后来想了想还是得模拟呀,直接根据时间来模拟即可,先是根据速度排个升序,然后模拟就行,添加一个vis数组来记录状态,当某条鱼空闲时,且还有鱼的时候,鱼的总数就少一条,当吃鱼的速度为1的时候要特判下,仔细分析好就行
参考代码
#include<bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int a[N];int main(){ ios_base::sync_with_stdio(0); int p,n,x; while (cin>>p>>n>>x) { for(int i = 0;i < n;i++) cin>>a[i]; sort(a,a+n); int s = 1; int q = 0; bool vis[N]; memset(vis,false,sizeof(vis)); for(int i = 1;i <= x;i++) { for(int j = 0;j < n;j++) { if(p == 0) break; if(i%a[j] == 0) { a[j] == 1?p--:p; if(vis[j]) vis[j] = false,q--; } else { if(!vis[j]) { p--; q++; vis[j] = true; } } if(p == 0 && q == 0) break; } if(p == 0 && q == 0) break; } cout<<p<<' '<<q<<endl; } return 0;}
- 如有错误或遗漏,请私聊下UP,thx
- ACM-ICPC北京赛区2017网络同步赛 题目5 : Cats and Fish【模拟】
- Cats and Fish 2017ACM-ICPC北京赛区/hihoCoder 1631
- ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- Cats and Fish2017北京赛区网络同步赛
- ACM-ICPC北京赛区2015网络同步赛E:Stamps
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum-(线段树)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目1 : Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目1 : Visiting Peking University
- Visiting Peking University 2017ACM-ICPC亚洲区(北京赛区)网络赛题目1
- ACM-ICPC北京赛区(2017)网络赛-题目9 : Minimum(线段树)
- ACM/ICPC北京赛区网络赛
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛
- ACM-ICPC北京赛区网络赛2017-minimum(线段树)
- hihoCoder 1227 The Cats' Feeding Spots(暴力)——ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
- hihoCoder 1227 The Cats' Feeding Spots && ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
- Cats and Fish(模拟)
- 【算法题】BFPRT算法:求第K小或者第K大的数
- 机器学习2-监督学习
- Java的线程异常处理器UncaughtExceptionHandler
- 简单图像分类与识别CNN,Tensorflow,Cifar10(吴恩达Deep Learning)
- 文章标题
- ACM-ICPC北京赛区2017网络同步赛 题目5 : Cats and Fish【模拟】
- 二维卷积详细解释
- OSG测试gl.h编译出错
- multi-labels classification
- OSGi简介
- Mysql批量插入事务插入性能对比
- 安卓正则补充
- JFrame窗口
- TCP协议中的三次握手和四次挥手(图解)