CodeForces - 768E Game of Stones —— nim博弈变种

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lngxling/article/details/82992870

题意:

在石堆中取石子,每次在一堆中取任意个,但是不能取这堆石子以前被取过的数量

思路:

nim的变形,求出每堆石子最多能被取多少次(依次取1个2个3个等),异或起来即可

这里的1个2个3个就相当于nim博弈里的每堆石子的1

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
#define max_ 200100
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-9
int n;
int num[60];
int main(int argc, char const *argv[]) {
    num[1]=1;
    int tot;
    for(tot=2;;tot++)
    {
        num[tot]=num[tot-1]+tot;
        if(num[tot]>60)
        break;
    }
    int ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        int k=upper_bound(num+1,num+1+tot,x)-num-1;
        ans^=k;
    }
    if(ans)
    printf("NO\n");
    else
    printf("YES\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Lngxling/article/details/82992870