题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6324
题意:小Q和小T正在玩游戏,一棵树上有n个点,每个点有一个权值,小Q先取任意个点(相邻的点不能同时取),剩余的都给小T。
题解:很显然小Q只要把二进制最高位的数字给取到就行了,因为剩余的数字小T不管怎么异或,也不能超过小Q的值。但还有一种情况,就是树上所有权值异或为0,那么此时就只能是平局了。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
const int maxn=100010;
typedef long long LL;
LL b[maxn];
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int sum=0;
for(int i=0 ; i<n ; i++)
{
scanf("%lld",&b[i]);
sum^=b[i];
}
for(int i=1 ; i<n ; i++)
{
int u,v;
scanf("%d%d",&u,&v);
}
if(sum==0)
{
puts("D");
}
else
{
puts("Q");
}
}
return 0;
}