题目链接:http://codeforces.com/contest/768/problem/E
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:
- The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones.
- The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move.
- The player who is unable to make a move loses.
Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.
In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.
Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.
First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles.
Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
1 5
NO
2 1 2
YES
In the first case, Sam removes all the stones and Jon loses.
In second case, the following moves are possible by Sam:
In each of these cases, last move can be made by Jon to win the game as follows:
题解:NIM游戏满足躲多堆SG函数的亦或和,我们知道对于一堆不加限制的X个石头,SG(X) = X, 但是加了限制后我们需要重新推算SG(X),首先明确SG(0) = 0;
SG(1) = MEX{SG(0)} = 1 // 唯一的转移方式
SG(2) = MEX{SG(0)} = 1 //是X=2可以转移的唯一方式,因为X=2无法转移到1,因为1->1,两次都移动1个不符合要求。
SG(3) = MEX{SG(0),SG(1),SG(2)} = 2//
同理SG(4) = MEX{SG(0),SG(1), (SG(3') } = {0,1,0} = 2 // 注意此时SG(3')由于4->3用了1,则SG(3')只能由SG(0)构成,则SG(3') = 1;
SG(5) = MEX{SG(0),SG(1),SG(2),SG(3'),SG(4'))} = {0,1,1,1,1} = 2 //
所以我们发现此时SG(X)和X的整数划分有关,并且划分出的数不能一个出现大于1次。
即SG(6) = {(0+6), 1+2+3} = 3;
SG(7) = {1+2+4} = 3;
即此时SG函数等价于这堆石头最多可以被取多少次。然后就时NIM定理应用。。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define x0 x0___
#define y0 y0___
#define pb push_back
#define SZ(X) ((int)X.size())
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define ALL(X) X.begin(),X.end()
#define RALL(X) X.rbegin(),X.rend()
#define rep(i,j,k) for(int i = j;i <= k;i ++)
#define per(i,j,k) for(int i = j;i >= k;i --)
#define mem(a,p) memset(a,p,sizeof(a))
const ll MOD = 1E9 + 7;
ll qmod(ll a,ll b,ll c) {ll res=1;a%=c; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%c;a=a*a%c;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template<typename T, typename S>
void upmax(T& a,S b){if(a<b) a=b;}
template<typename T, typename S>
void upmin(T& a,S b){if(a>b) a=b;}
template<typename T>
void W(T b){cout << b << endl;}
void gettle() {while(1);}
void getre() {int t=0;t/=t;}
/
/
/
/
const int N = 1E6 + 7;
int a[N];
int main()
{
int n, t;
scanf("%d", &n);
int res = 0;
rep (i,1,n) {
scanf("%d",&t);
rep (j,1,60) {
t -= j;
if(t < 0) {
a[i] = j - 1;
break;
}
}
}
rep(i,1,n) res ^= a[i];
puts(res ? "NO" : "YES");
return 0;
}