2017年ICPC中国大陆区域赛真题(上)A题

题目网址点击进入

problem
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.

Input
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).

Output
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.

Sample Input
2 1 1
1
8 3 5
1 3 4
4 5 1
5 4 3 2 1
Sample Output
1 0
0 1
0 3

大致题意
m条鱼n只猫在x分钟以后,还剩下几条完整的鱼和几条没吃完(吃一半)的鱼,当两只猫同时吃完自己的鱼时,吃的快的猫优先拿鱼
第一行输入m,n,x
接下来一行n个数,表示每只猫吃鱼的速度
输出剩下几条鱼和几条没吃完的鱼

思路
首先是猫的吃鱼速度,谁先吃完谁先得到鱼,于是就需要一个排序,将速度快的猫排放在前面
猫的数量n为100以内,x分钟在1000以内完全可以利用暴力法解决问题
于是首先需要一个for来循环x,第一分钟时候哪一些猫可以拿到新鱼,吃了多少,第二分钟哪一些猫可以拿到新鱼
以此类推,在这个for里面,再放一个排序好的猫顺序for循环,来发放新鱼以及更新每只猫吃鱼情况

代码

#include<stdio.h>
#include<algorithm>
using namespace std;
struct sy///一个结构体,speed速度,schedul此条鱼吃的怎么样
{
    long long int speed,schedule;
}cat[1005];
bool cmp(sy a,sy b)
{
    return a.speed<b.speed;///按照吃鱼速度排序
}
int main()
{
    long long int n,m,x;
    while (scanf("%lld %lld %lld",&m,&n,&x)!=EOF)
    {
        for (long long int i=0;i<n;i++)
        {
            scanf("%lld",&cat[i].speed);
            cat[i].schedule=0;
        }
        sort(cat,cat+n,cmp);
        long long int num=m;///还剩几条鱼
        long long int over=0;///吃的鱼中几条吃完了
        for (long long int i=1;i<=x;i++)
        {
            for (long long int j=0;j<n;j++)
            {
                if (num>0&&cat[j].schedule==0)
                {
                    num--;///如果还有鱼,且这只猫已经吃完上一条鱼
                    cat[j].schedule++;///发新的鱼,且这分钟吃了一口
                }else if (num>0&&cat[j].schedule!=0)
                {
                    cat[j].schedule++;///如果还没吃完这条鱼继续吃
                }
                if (cat[j].schedule==cat[j].speed)
                {
                    cat[j].schedule=0;///吃完了鱼,吃鱼情况归0
                    over++;///吃的鱼,这条吃完了++;
                }
            }
        }
        printf("%lld %lld\n",num,m-num-over);///剩下num,吃的鱼里面没吃完整的
        ///没吃完整=发的鱼-吃完整的=总数-剩下鱼-吃完整的
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值