Daizhenyang's Coin(Nim&博弈論)
思路:中心思想是將該遊戲轉化爲多個子遊戲進行和。
這裏的子游戲是指:當只有一個硬幣朝上位於位置的
因爲有重複需要先去重,然後再異或和。
令U向上,D向下。
初始化 對應情況 (D) 。無論有多少個都是屬於這個情況。因爲沒有硬幣朝上肯定是輸。
(U) 的後繼狀態只有,所有
同理
依次類推找規律可得, .而所有的值的二進制1的個數都爲奇數。所以判斷一下即可。具體證明見別的大佬的博客。。還在學習中。
傳送門
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define mst(a) memset(a,0,sizeof a)
map<int,int>mp;
int n;
/*
bool jg(int x){ //計算二進制中1的個數
int cnt=0;
while(x){
if(x&1) cnt++;
x>>=1;
}
return (cnt&1);
}
*/
int fun(int x){
if((__builtin_popcount(2*x))&1) return 2*x;
return 2*x+1;
}
int main(){
while(cin>>n){
mp.clear();
int ans=0;
for(int i=1,x;i<=n;i++){
cin>>x;
if(!mp[x]) mp[x]=1,ans^=fun(x);
}
if(!ans) puts("Yes");
else puts("No");
}
return 0;
}