[agc017d]Game on Tree
来源:互联网 发布:自己拍电影知乎 编辑:程序博客网 时间:2024/06/06 02:40
前言
现在看到游戏题居然已经不会sg了。
题意
以1为根的树,两人轮流操作,每次切掉一个子树,不能操作者输。
sg函数
首先容易用归纳法证明一颗树上接一个节点的sg值相当于原来+1。
然后你注意到一颗树可以拆分成若干颗儿子上接一个节点,等价于原来的游戏。
于是就是简单的组合游戏题了。
#include<cstdio>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;const int maxn=100000+10;int h[maxn],go[maxn*2],nxt[maxn*2];int i,j,k,l,t,n,m,tot;void add(int x,int y){ go[++tot]=y; nxt[tot]=h[x]; h[x]=tot;}int dfs(int x,int y){ int l=0,t=h[x]; while (t){ if (go[t]!=y) l^=dfs(go[t],x)+1; t=nxt[t]; } return l;}int main(){ scanf("%d",&n); fo(i,1,n-1){ scanf("%d%d",&j,&k); add(j,k);add(k,j); } if (dfs(1,0)) printf("Alice\n");else printf("Bob\n");}
阅读全文
0 0
- [agc017d]Game on Tree
- CodeForces 280C Game on Tree 概率
- HackerRank - number-game-on-a-tree
- codeforces 280C Game on Tree
- CodeForce 280C Game on Tree -- 树形dp求期望
- codeforces 280 C Game on Tree (离散概率)
- Codeforces 280C Game on Tree 树形期望dp
- Codeforces 280 C. Game on Tree (概率与期望)
- AGC 017D Game On Tree 博弈(Hackenbush删边)
- Round #172 (Div. 1) C. Game on Tree——概率
- Codeforces 280C Game on Tree 概率dp 树上随机删子树 求删完次数的期望
- game on demand
- <cf>Game on Paper
- CodeForces -Game on Paper
- WOJ1026-Game On Checkerboard
- Ural 1282. Game Tree
- hdu3094 A tree game
- URAL 1282 Game Tree
- Appium click事件 报错 Injecting to another application requires INJECT_EVENTS permission解决
- HDU-5970 推公式+分块
- SSH入门项目-7-差缺补漏
- String Stringbuff Stringbuilder的区别(初级
- 设计模式【单例模式Singleton Pattern】
- [agc017d]Game on Tree
- 实时通讯之Socket.io
- 对于 iOS 开发,人工智能意味着什么?
- bzoj 2161: 布娃娃
- 第四周—项目2
- Linux 指令与文件的搜寻 —— which whereis locate updatedb find
- Java 设计模式之中介者模式
- netty-socketio即时通讯
- 搭建Docker Swarm集群实战(一)(服务发现使用consul)