hdu5996 階梯nim博弈

第一次接觸到階梯nim博弈 看了這篇博客,講得比較清楚:http://blog.csdn.net/kk303/article/details/6692506

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5996

大意就是給一顆樹 樹的節點上放有石子,每次只能把石子往父節點移動一下,規定不能移動者輸。

看了階梯博弈後大概就能懂這題的意思了,直接把深度爲奇數的節點異或起來就可以了

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;
#define LL long long

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		int d[100005];
		d[0] = 0;
		for(int i = 1;i<n;i++)
		{
			int temp;
			scanf("%d",&temp);
			d[i] = d[temp]+1;
		}
		int ans = 0;
		for(int i = 0;i<n;i++)
		{
			int temp;
			scanf("%d",&temp);
			if(i==0)
			continue;
			if(d[i]%2==1)
			{
				ans ^= temp;
			}
		}
		if(ans!=0)
		{
			printf("win\n");
		}
		else
		{
			printf("lose\n");
		}
	 } 
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章