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
阅读全文
0 0