Cats and Fish2017北京赛区网络同步赛

来源:互联网 发布:无法复制淘宝助理 编辑:程序博客网 时间:2024/05/21 13:54
题目链接:http://hihocoder.com/problemset/problem/1631

首先根据吃鱼的速度从小到大排序,然后从1到x按着时间轴枚举猫的行为,如果是吃完一条判断一下他的状态是正在吃鱼还是没有在吃鱼,若正在吃鱼则不完整的鱼p减一同时把状态调整为未吃鱼,否则直接将剩余的完整的鱼-1;若行为是吃鱼未吃完,也即不能整出,再根据猫的状态做相应的调整

AC代码:

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn = 5000 + 10;int a[maxn],eat[maxn];  //eat值为一代表正在吃,0代表未吃int main(){    int m,n,x;    while(scanf("%d%d%d",&m,&n,&x) == 3)    {        for(int i = 0; i < n; i++)            scanf("%d",&a[i]);        int q = 0;  //残缺的鱼        int p = m;  //完整的鱼        sort(a,a + n);        memset(eat,0,sizeof(eat));        //枚举时间轴        for(int i = 1; i <= x; i++)        {            if(!p) break;            for(int j = 0; j < n; j++)            {                if(!p) break;                if(i % a[j] == 0)                {                    if(eat[j])                    {                        eat[j] = 0;                        q--;                    }                    else p--;                }                else                {                    if(eat[j]) continue;                    else                    {                        eat[j] = 1;                        q++;                        p--;                    }                }            }        }        printf("%d %d\n",p,q);    }    return 0;}
阅读全文
1 0
原创粉丝点击