hdu 1524 A Chess Game
2012-10-17 09:38
316 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1524
博弈 用SG处理
博弈 用SG处理
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<queue> #include<map> #include<stack> #include<algorithm> #include<cmath> using namespace std; //#pragma comment(linker,"/STACK:1000000000,1000000000") #define LL long long const int N=1005; const int M=100005; int Nim ; int head ; int I,next[M],k[M]; void Add(int i,int j) { k[I]=j; next[I]=head[i]; head[i]=I++; } int dp(int x)//求x对应到Nim里的值 { if(Nim[x]!=-1) return Nim[x]; bool had ; memset(had,false,sizeof(had)); for(int t=head[x];t!=-1;t=next[t]) { had[ dp( k[t] ) ]=true; } for(int i=0;i<N;++i) { if(!had[i])//第一个到不了的值 {Nim[x]=i;break;} } return Nim[x]; } int main() { //freopen("data.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF) { memset(head,-1,sizeof(head)); I=0; int m; for(int i=0;i<n;++i) { scanf("%d",&m); while(m--) { int j; scanf("%d",&j); Add(i,j); } } memset(Nim,-1,sizeof(Nim)); while(scanf("%d",&m),m) { int flag=0; while(m--) { int tmp; scanf("%d",&tmp); flag=(flag^dp(tmp));//S-Nim 异或 } if(flag) printf("WIN\n"); else printf("LOSE\n"); } } return 0; }
相关文章推荐
- hdu 1524 A Chess Game
- HDU 1524 A Chess Game [SG函数]【博弈】
- HDU 1524 A Chess Game(SG博弈)
- HDU 1524 A Chess Game (SG函数模板题)
- HDU_1524 A Chess Game (sg函数)
- hdu 1524 A Chess Game
- SG 函数 hdu1524 & poj 2425 hdu1524 A Chess Game
- HDU 1524 A Chess Game (有向无环图SG博弈)
- HDU 1524 A Chess Game(SG函数)
- hdu 1524 A Chess Game (SG)
- POJ 2425 && HDU 1524 A Chess Game(博弈论)
- (step 8.2.13)hdu 1524(A Chess Game)
- HDU 1524 A Chess Game 【SG函数】
- hdu1524 A Chess Game
- hdu 1524 A Chess Game 博弈论
- (step 8.2.13)hdu 1524(A Chess Game)
- hdu 1524 A Chess Game
- HDU 1524 - A Chess Game(SG)
- sg函数_____A Chess Game( hdu 2425 )
- 杭电1524 A Chess Game(博弈--- 图)