Cats and Fish(模拟)

#1631 : 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
/*

题目大意:
    有n只猫,第i只猫吃完一条鱼的时间是Ci分钟,时间短的优先有鱼吃,现在有m条鱼,
n只猫同时开始吃,问在t分钟后剩余的完整的鱼的条数和不完整的鱼的条数(即正在吃的
条数)。

题解:
    模拟过程,此题时间短的优先吃到鱼,所以应先排一下序。模拟每一分钟的情况。
进行下去的条件是所有猫吃过以及正在吃的鱼的数量不超过题目所给的鱼的数量和题目
所给的时间限制,满足其中一个条件就可以不必再进行下去了。用ans表示正在吃的鱼
的数量,num表示吃过的鱼的数量。其次,用当前时间对Ci进行取模,如果结果为0,则
说明此时i猫刚好吃掉鱼,取消对i的标记,ans--,num++;若不为0时,表示正在吃,标记
当前的i,ans--。
    最后要注意的是,若是还未到t分钟,最后需要将剩余的时间和每个正在吃鱼的猫的
Ci相比,若大于Ci,num++,ans--.

*/

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main()
{
    int m,n,t,time[1010],i,tt,book[1010],j,f,ans,k;
    int ans;//正在吃但还没有吃完的鱼的数量ans;
    int num;//已经吃完的鱼的数量num;
    while(~scanf("%d%d%d",&m,&n,&t))
    {
        for(i=0; i<n; i++)
            scanf("%d",&time[i]);
        sort(time,time+n);
        memset(book,0,sizeof(book));
        int num=0;
        ans=0;
        f=0;
        for(i=1; i<=t; i++)
        {
            for(j=0; j<n; j++)
            {
                int p=i%time[j];
                if(p==0)//第i只猫吃完一条鱼时;
                {
                    if(book[j])//这只猫之前被标记过;
                    {
                        ans--;
                        book[j]=0;//取消标记;
                    }
                    num++;
                }
                else//还未吃完时;
                {

                    if(!book[j])
                    {
                        book[j]=1;//标记;
                        ans++;
                    }
                }
                if(num+ans>=m)//判断鱼是否还有剩下的;
                {
                    f=1;
                    break;
                }
            }
            if(f)break;
        }
        tt=t-i+1;//结束后剩余的时间tt;
        for(i=0; i<n; i++)
            if(tt>=time[i]&&book[i])//判断剩余的时间里还能否吃完鱼;
            {
                ans--;
                num++;
            }
        printf("%d %d\n",m-(num+ans),ans);
    }
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值