现在的位置: 首页 > 综合 > 正文

hdu 5090 Game with Pearls 2014上海全国邀请赛——题目重现

2018年04月25日 ⁄ 综合 ⁄ 共 933字 ⁄ 字号 评论关闭

三门final exams结束之后继续我的水题大作战~~^^~~

这一题我第一眼还以为是博弈。。。最后一看N才100,直接枚举填数就可以了。

我之前还考虑会不会有这种case,比如已存在a,b,然后a+xK补b的位置,b+yK补c  (c=b+yK),最后发现因为直接是K的倍数,直接a+(x+y)K补c不就行了,原先存在的数不会变动。简直智硬啊。。。

所以如果有多个a,直接+K,+2K,+3K..从小到大枚举即可。

#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include <ctype.h>
using namespace std;
//hdu 5090;
int N;
int M;
int K;
int a[1000];
int main()
{
    freopen("input.txt","r",stdin);
    // freopen("data.txt","r",stdin);
     //freopen("out1.txt","w",stdout);
    scanf("%d",&M);
    for(int i=0;i<M;i++)
    {
        memset(a,0,sizeof(a));
        scanf("%d %d",&N,&K);
        for(int i=1;i<=N;i++)
        {
            int t=0;
            scanf("%d",&t);
            a[t]++;
        }
        for(int i=1;i<=N;i++)
        {
            if(a[i]>1)
            {
                int cnt=1;
                while(a[i]>1&&(i+cnt*K)<=N)
                {
                    if(a[i+cnt*K]==0)
                    {
                        a[i]--;
                        a[i+cnt*K]++;
                        //break;
                    }
                    cnt++;
                }
            }
        }
        bool flg=true;
        for(int i=1;i<=N;i++)
        {
            if(a[i]==0)
            {
                printf("Tom\n");
                flg=false;
                break;


            }
        }
        if(flg)
        {
            printf("Jerry\n");
        }

    }

    return 0;
}



抱歉!评论已关闭.