HDU 5996 dingyeye loves stone (树形博弈)
来源:互联网 发布:sql数据库是什么 编辑:程序博客网 时间:2024/05/04 20:24
dingyeye loves stone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 59 Accepted Submission(s): 34
Problem Description
dingyeye loves play stone game with you.
dingyeye has ann -point tree.The nodes are numbered from 0 to n−1 ,while the root is numbered 0 .Initially,there are a[i] stones on the i -th node.The game is in turns.When one move,he can choose a node and move some(this number cannot be0 ) of the stones on it to its father.One loses the game if he can't do anything when he moves.
You always move first.You want to know whether you can win the game if you play optimally.
dingyeye has an
You always move first.You want to know whether you can win the game if you play optimally.
Input
In the first line, there is an integer T indicating the number of test cases.
In each test case,the first line contains one integern refers to the number of nodes.
The next line containsn−1 integers fa[1]⋯fa[n−1] ,which describe the father of nodes 1⋯n−1 (node0 is the root).It is guaranteed that 0≤fa[i]<i .
The next line containsn integers a[0]⋯a[n−1] ,which describe the initial stones on each nodes.It is guaranteed that 0≤a[i]<134217728 .
1≤T≤100 ,1≤n≤100000 .
It is guaranteed that there is at most7 test cases such that n>100 .
In each test case,the first line contains one integer
The next line contains
The next line contains
It is guaranteed that there is at most
Output
For each test case output one line.If you can win the game,print "win".Ohterwise,print "lose".
Sample Input
2201000 140 1 02 3 3 3
Sample Output
winlose传送门: http://acm.hdu.edu.cn/showproblem.php?pid=5996
思路: 树形博弈。 对于第 2、4、6层的数不用考虑(连续上移两次即可);对于第1、3、5、7层的数,如果全部节点权值抑或,最后得到0(对一个高度为奇数的点进行的操作,即移动到高度为偶数进行处理)。
#include <queue>#include <functional>#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <stack>#include <vector>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <assert.h>#define REP(i,k,n) for(int i=k;i<n;i++)#define REPP(i,k,n) for(int i=k;i<=n;i++)#define scan(d) scanf("%d",&d)#define scann(n,m) scanf("%d%d",&n,&m)#define mst(a,k) memset(a,k,sizeof(a));#define LL long long#define eps 1e-8#define INF 0x3f3f3f3f#define inf INF*INF#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))#define mod 1000000007using namespace std;#define N 100005int f[N];int num[N];int ans;int main(){ int t; scan(t); while(t--){ int n; scan(n); REP(i,1,n){ int nn; scan(nn); f[i] = f[nn] + 1; } REP(i,0,n) scan(num[i]); ans = 0; REP(i,1,n){ if(f[i]&1) ans^=num[i]; } if(!ans) printf("lose\n"); else printf("win\n"); }}
0 0
- HDU 5996 dingyeye loves stone (树形博弈)
- HDU 5996 dingyeye loves stone (DFS+博弈)
- HDU 5996 BestCoder Round #90 1002 dingyeye loves stone 博弈
- hdu 5996 dingyeye loves stone nim同阶博弈
- 【HDU 5996 dingyeye loves stone】+ 尼姆博弈
- HDU 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- 【hdu 5996】dingyeye loves stone
- HDU 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- hdu 5996 dingyeye loves stone
- HDU 5996 dingyeye loves stone
- hdoj 5996 - dingyeye loves stone(阶段博弈)
- HDOJ 5996 dingyeye loves stone(阶梯博弈)
- dingyeye loves stone(阶梯博弈+vector)
- HDU 5996 dingyeye loves stone(Nim 变形)
- HDU 5996 dingyeye loves stone(阶梯尼姆博弈)——BestCoder Round #90
- java第一周的周总结
- 编程学习分享
- JavaScript基础系列(变量与类型)
- 51nod 1125 交换机器的最小代价
- Android自定义PopupWindow显示在控件上方或者下方
- HDU 5996 dingyeye loves stone (树形博弈)
- String s = Null 与 s="" 有什么区别?null意思是不存在,""意思是存在,但是值为空 null表示还没new出对象,就是还没开辟空间 “”表示new除了对象,但是这个对象装的是空
- OpenCV学习之路之一开发环境搭建(W7+Qt4+opencv2+mingw)
- Scrapy爬虫+Tkinter爬取天猫热门商品(一)
- ubuntu16.04 mysql修改datadir的折腾
- Eclipse+PyDev离线配置Python开发环境
- Java IO流学习笔记2
- 初识dubbo
- MVC MVP MVVM模式的浅谈