ZOJ 3666 Alice and Bob(博弈)
来源:互联网 发布:lda主题模型 python 编辑:程序博客网 时间:2024/05/14 12:02
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
比较明显的树形博弈,求个SG函数就行了。
但是求后继判断是递归的,RE到死,结果是爆栈了。
改成非递归。
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666
#include<iostream>#include<cstdio>#include<map>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#include<set>#include<string>#include<queue>#include<stack>#define inf 100000005#define M 4005#define N 10005#define maxn 300005#define eps 1e-10#define zero(a) fabs(a)<eps#define Min(a,b) ((a)<(b)?(a):(b))#define Max(a,b) ((a)>(b)?(a):(b))#define pb(a) push_back(a)#define mp(a,b) make_pair(a,b)#define mem(a,b) memset(a,b,sizeof(a))#define LL unsigned long long#define MOD 1000000007#define lson step<<1#define rson step<<1|1#define sqr(a) ((a)*(a))#define Key_value ch[ch[root][1]][0]#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;vector<int>e[N];int n,sg[N];struct Rec{ int v; bool vis[M]; Rec() {} Rec(int _v): v(_v) {mem(vis,0);}};int cur[N];int get_sg(int root){ if (sg[root]!=-1) return sg[root]; mem(cur,0); stack<Rec> q; q.push(Rec(root)); while (!q.empty()) { loop: int u=q.top().v; sg[u]=0; for (int& i=cur[u]; i<e[u].size(); i) { int v=e[u][i]; if (sg[v]==-1) { q.push(Rec(v)); goto loop; } else { q.top().vis[sg[v]]=1; i++; } } for (int i=0; i<M; i++) if (!q.top().vis[i]) { sg[u]=i; break; } q.pop(); } return sg[root];}int main(){ int cas=0; // freopen("1.in","r",stdin); while(scanf("%d",&n)!=EOF) { printf("Case %d:\n",++cas); for(int i=1;i<=n;i++) e[i].clear(); for(int i=1;i<n;i++) { int k,v; scanf("%d",&k); while(k--) { scanf("%d",&v); e[i].pb(v); } } mem(sg,-1); int q; scanf("%d",&q); while(q--) { int k,v; int ans=0; scanf("%d",&k); while(k--) { scanf("%d",&v); ans^=get_sg(v); } // for(int i=1;i<=n;i++) cout<<i<<" "<<get_sg(i)<<endl; puts(ans?"Alice":"Bob"); } } return 0;}
- ZOJ 3666 Alice and Bob(博弈)
- ZOJ 3666 Alice and Bob 基础博弈
- ZOJ 3666 Alice and Bob(博弈 sg 函数入门)
- Alice and Bob(博弈)
- XTU 1209 Alice and Bob (博弈)
- ZOJ 3529 A Game Between Alice and Bob(博弈)
- zoj 3666 Alice and Bob , SG函数
- ZOJ 3529 - A Game Between Alice and Bob(素因子+博弈)
- 【Hrbust】 Alice and Bob (博弈)
- [UVALive5760] Alice and Bob && 博弈
- 【博弈】Alice and Bob CodeForces
- NYOJ 题目1053 Alice and Bob (N)(博弈)
- CodeForces 347C Alice and Bob(博弈)
- codeforces 347 c Alice and Bob(博弈 && 数学)
- ZOJ Problem Set - 3666 Alice and Bob(SG)
- [博弈] hdu 4371 alice and bob
- UVA 1500 - Alice and Bob(博弈)
- UVA - 1500 Alice and Bob (dp+博弈)
- 解析后存储数据库
- ecshop如何增加产品描述编辑器
- 类型转换
- 北大ACM poj1068 Parencodings
- 真正优秀的程序员有哪些与众不同之处?
- ZOJ 3666 Alice and Bob(博弈)
- 权重
- ecshop商品详情页添加任意字段的方法
- 了解数据库存储方式
- Cocos-2d 游戏进度条加载CCProgressTimer实现
- 继承和复合
- 什么是句柄
- AIX下awk语言的输出函数printf
- 创建窗口--java---frame