HDU 5090 Game with Pearls (贪心)

一道贪心的题,因为最小的不能由别的转化,所以每次贪心找最小的,其余的转化成大的。

从小到大,最小的如果不存在那么就break,否则减去一个,剩下的加k继续判断。

#include<cstdio>
#include<cstring>
const int maxn = 300;
int cnt[maxn];


int main()
{
    int T;
    scanf("%d",&T);
    int n,k;
    while(T--){
        memset(cnt,0,sizeof(cnt));
        scanf("%d%d",&n,&k);
        int t;
        for(int i = 0; i < n; i++){
            scanf("%d",&t);
            cnt[t]++;
        }
        int flag = 1;
        for(int i = 1; i <= n; i++){
            if(!cnt[i]){
                flag = 0;break;
            }
            cnt[i+k] += cnt[i]-1;
        }
        printf("%s
",flag?"Jerry":"Tom");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/jerryRey/p/4654286.html