Cats and Fish

HihoCoder - 1631

#include <bits/stdc++.h>
using namespace std;
struct node
{
int f; // f当前是否有鱼吃 v是吃鱼的速度
int v;
} s[1005];
bool cmp(struct node a,struct node b)
{
return a.v < b.v;
}
int main()
{
int n,m,x;
while(~scanf("%d %d %d", &m, &n, &x))
{
for(int i = 1; i <= n; i ++)
{
scanf("%d",&s[i].v);
s[i].f = 0;
}
sort(s + 1, s + 1 + n, cmp);
int sum1 = m, sum2 = 0;
for(int i = 0; i <= x; i ++)
{
for(int j = 1; j <= n; j ++)
{
if(i % s[j].v == 0) // 如果当前是这个猫的吃鱼的速度的倍数,那么肯定能够给ta吃。
s[j].f = 0;
if(sum1 <= 0) // 如果没有鱼了,就不用继续了
continue;
else // 否则,当前这只没有鱼吃的猫会选择一条鱼吃
{
if(s[j].f == 0 && i != x) // i是从0开始
{
s[j].f = 1;
sum1--;
}
}
}
}
for(int j = 1; j <= n; j ++) // 还有标记的猫就是正在第x秒在吃鱼的啦
{
if(s[j].f == 1)
sum2 ++;
}
printf("%d %d\n",sum1,sum2);
}
return 0;
}
05-23 10:13