【HDU3094】A tree game 博弈,树形删边游戏
来源:互联网 发布:windows为什么要激活 编辑:程序博客网 时间:2024/06/05 14:21
转载请注明出处:http://blog.csdn.net/vmurder/article/details/42653129
其实我就是觉得原创的访问量比未授权盗版多有点不爽233。。。
题意:给一颗树,每次可以删掉一条与节点1(root)的连通的边,两人轮流操作,谁不能操作谁输。
题解:
只能套公式:
Colon原理:SG(x)=XOR{SG(y)+1|y是x的子结点}。
好了。水了。
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 101000using namespace std;struct KSD{int v,next;}e[N<<1];int head[N],cnt;inline void add(int u,int v){e[++cnt].v=v;e[cnt].next=head[u];head[u]=cnt;}int n;int sg[N];void dfs(int x,int p){int i,v;sg[x]=0;for(i=head[x];i;i=e[i].next){v=e[i].v;if(v==p)continue;dfs(v,x);sg[x]^=(sg[v]+1);}}int main(){int i,j,T;int a,b;for(scanf("%d",&T);T--;){cnt=1;memset(head,0,sizeof(head));scanf("%d",&n);for(i=1;i<n;i++){scanf("%d%d",&a,&b);add(a,b),add(b,a);}dfs(1,0);if(sg[1])puts("Alice");else puts("Bob");}return 0;}
0 0
- 【HDU3094】A tree game 博弈,树形删边游戏
- hdu3094—A tree game-(树形博弈)
- hdu3094 A tree game----树的删边游戏
- hdu3094 A tree game
- HDU 3904 A tree game(树的删边游戏,树形图博弈)
- hdu 3094 A tree game (树形删边游戏)
- 【POJ3710】Christmas Game 博弈 有限制的图上删边游戏(树形删边游戏进化1)
- POJ 3710 Christmas Game (Tarjan求连通分量+树形博弈删边游戏)
- HDU 3094 A tree game 树的删边游戏
- HDU 3094 A tree game(树上删边游戏)
- hdu 3094 A tree game (博弈 树的删边问题)
- [POJ3710]Christmas Game(博弈树的删边游戏)
- 【博弈】【SG函数】【HUST 1612】A new tree game
- poj 3710 Christmas Game (树形删边游戏)
- Chomp game博弈游戏
- Nim Game 博弈游戏
- Play a game + 博弈
- A Multiplication Game + 博弈
- QML之虚拟键盘
- 进入csdn,写我的博客,很开心
- 一些C++著名类库
- unity3D 内存管理——对象池(Object Pool)
- rubymine 安装破解
- 【HDU3094】A tree game 博弈,树形删边游戏
- 通过代码创建Java项目
- 迷你浏览器——WebView学习
- jquery去除回车换行
- HDOJ 题目3456 Universal Oracle(模拟,水)
- 论文中的图目录与表目录
- nagios插件之监控单个tomcat线程数
- Java网络编程-代理
- 程序存储问题