HDU 5996 dingyeye loves stone (DFS+博弈)
来源:互联网 发布:东东数据cf刷枪教程 编辑:程序博客网 时间:2024/06/10 18:40
dingyeye loves stone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 98 Accepted Submission(s): 56
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 be 0 ) 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 (node 0 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
Source
BestCoder Round #90
Recommend
wange2014 | We have carefully selected several similar problems for you: 5998 5997 5994 5993 5992
题意:有一棵树,树的每个节点上都有一定数量的石子,现在给出每个节点的父亲节点,要求:每次可以将节点的石子移动到其父亲节点上(移动的石子数不能为0),当不能操作时输:
思路:DFS求每个节点的深度,对深度为奇数的进行异或;
#include<stdio.h>#include<string.h>#include<algorithm>#include<vector>using namespace std;vector<int>g[100100];int num[100100];int depth[100100];int ans,n;void dfs(int i,int d){ if(d&1) ans^=num[i]; for(int j=0;j<g[i].size();j++) { depth[g[i][j]]=depth[i]+1; dfs(g[i][j],depth[g[i][j]]);}}int main(){int t,i,j,m,x;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;i++){g[i].clear();depth[i]=0;}for(i=1;i<n;i++){scanf("%d",&x);g[x].push_back(i);}for(i=0;i<n;i++){scanf("%d",&num[i]);}ans=0;dfs(0,0);if(ans)printf("win\n");elseprintf("lose\n");}return 0;}
0 0
- HDU 5996 dingyeye loves stone (DFS+博弈)
- HDU 5996 dingyeye loves stone (树形博弈)
- 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
- 51Nod - 1289
- H5表单验证不得为空,自定义提示语
- MFC之三文本文件读写
- centos(vm)下单机安装flume1.6.0(x86)
- javaWEB总结(12):JSP页面的九个隐含对象
- HDU 5996 dingyeye loves stone (DFS+博弈)
- MySQL ORDER BY 排序 IF 及 IN
- Android studio新项目提交到git
- js中的Number对象操作
- servletconfig,servletcontext 笔记
- Java语言基础(六)之 —— 选择结构(if语句)
- MFC自绘Button按钮分析和实现
- 防止网站内容被采集
- 剑指offer学习笔记(Java实现)(1-10)