UVALive/LA 5059 Play with Stones 组合游戏/SG定理
2013-08-04 18:58
537 查看
#include <iostream> using namespace std; #define LL long long LL SG(LL x) { return x%2==0?x/2:SG(x/2); } int main() { LL T; cin>>T; while(T--) { LL i,n,a,v=0; cin>>n; for(i=0;i<n;i++) { cin>>a; v^=SG(a); } if(v)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } /* 组合游戏:一个状态是必败状态当且仅当它的所有后继都是必败状态 一个状态是必胜条件当且仅当它至少有一个后继是必败状态 组合游戏的和。假设有k个组合游戏G1,G2,...Gk,可以定义一个新游戏,在每个回合中, 当前游戏可以任选一个子游戏Gi进行一次合法操作,而让其他游戏的局面保持不变,不鞥操作的游戏者输。 这个新游戏称为G1,G2,...,G3的和 SG函数和SG定理。对于任意状态x,定义SG(x)=mex(S),其中S是x的后继状态的SG函数值集合,mex(S)表示不在S内的最小非负 整数。SG(x)当且仅当x为必败状态.游戏和的SG函数SG函数等于各子游戏SG函数的Nim和。 Bouton定理:状态(x1,x2,x3)为必败状态当且仅当x1^x2^x3=0,称为Nim和。可看做SG定理在Nim游戏中的运用 */ /*通过SG定理求得SG函数,然后通过找规律解决问题,SG(n)=n/2(n为偶数),SG(n)=SG(n/2)(n为奇数) #include <iostream> #include <string.h> using namespace std; #define maxn 100 int SG[maxn]; int vis[maxn]; int main() { SG[1]=0; for(int i=2;i<=30;i++) { memset(vis,0,sizeof(vis)); for(int j=1;j*2<=i;j++)vis[SG[i-j]]=1; for(int j=0;;j++) if(!vis[j]) { SG[i]=j; break; } cout<<SG[i]<<endl; } return 0; } */
相关文章推荐
- UVALive 5059 Play with Stones SG函数,难度较低
- uvalive 5059 Playing With Stones(组合游戏,SG函数)@
- UVA 10561 Treblecross 组合游戏/SG定理
- UVaLive5059 Playing With Stones
- UVaLIve 2889 | LA 2889 | UVa 12050 - Palindrome Numbers (组合数学)
- UVALive 5059 C Playing With Stones
- UVA 12293 Box Game 组合游戏/SG定理+找规律
- UVALive 5059 C - Playing With Stones 博弈论Sg函数
- UVALive 7040 Color (容斥定理 + 递推求逆元 + 组合数 + 快速幂)
- UVa 11806 Cheerleaders (组合&逆向思维||容斥定理)
- UVaLive/LA 6800 The Mountain of Gold?(BellmanFord判负环+记忆化搜索)
- UVALive 3703 (LA 3703) Billing Tables Trie树
- uvalive 5760 Alice and Bob (组合游戏,dp)
- 【排列组合】UVALive - 6926 Maximum Score
- UVALive - 5110 Square-Free Numbers ( 唯一分解定理
- 【筛法求素数】【推导】【组合数】UVALive - 7642 - Prime Distance
- UVaLive/LA 6801 Sequence(DP)
- UVALive-8079 Making a Team 排列组合公式化简
- UVALive(LA) 4487 Exclusive-OR(带权并查集)
- UVaLive 2678(LA)Subsequence SEERC 2006 题解