您的位置:首页 > 其它

La 5059 - Playing With Stones

2013-09-08 16:24 316 查看
题目:La 5059 - Playing With Stones

思路:SG打表题

数据范围很大,一个一个搜不现实,输出前几项的SG值,发现偶数项按整数递增,而剩下的奇数项又是新的一个这样的一个序列,所以递归一下就ok

// 观察一下前几项
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
set<int>s;
const int maxn = 2001;
int sg[maxn];
int get()
{
    int i=0;
    while(s.count(i))
        i++;
    return i;
}
int main()
{
    sg[1]=0;
    for(int i=2;i<maxn;i++)
    {
        s.clear();
        for(int j=1;j*2<=i;j++) // j为从i中拿走不超过一半的
            s.insert(sg[i-j]);
        sg[i]=get();
    }
    for(int i=0;i<100;i++)
        cout<<i<<" "<<sg[i]<<endl;
    return 0;
}


// AC 代码
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
long long sg(long long n)
{
    if(n&1)
        return sg(n/2);
    else
        return n/2;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        long long x;
        scanf("%d",&n);
        long long ans=0;
        while(n--)
        {
            scanf("%lld",&x);
            ans^=sg(x);
        }
        if(ans)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: