Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2,…,n, connected by n−1 bidirectional edges. The i-th vertex has the value of wi.
In this game, Little Q needs to grab some vertices on the tree. He can select any number of vertices to grab, but he is not allowed to grab both vertices that are adjacent on the tree. That is, if there is an edge between x and y, he can’t grab both x and y. After Q’s move, Little T will grab all of the rest vertices. So when the game finishes, every vertex will be occupied by either Q or T.
The final score of each player is the bitwise XOR sum of his choosen vertices’ value. The one who has the higher score will win the game. It is also possible for the game to end in a draw. Assume they all will play optimally, please write a program to predict the result.
Input
The first line of the input contains an integer T(1≤T≤20), denoting the number of test cases.
In each test case, there is one integer n(1≤n≤100000) in the first line, denoting the number of vertices.
In the next line, there are n integers w1,w2,…,wn(1≤wi≤109), denoting the value of each vertex.
For the next n−1 lines, each line contains two integers u and v, denoting a bidirectional edge between vertex u and v.
Output
For each test case, print a single line containing a word, denoting the result. If Q wins, please print Q. If T wins, please print T. And if the game ends in a draw, please print D.
Sample Input
1
3
2 2 2
1 2
1 3
Sample Output
Q

大体意思就是说Q和T两个人玩一个游戏,有n个点每个点有一个权值,Q选一部分不相邻的点,T拿走剩下全部点,两个人选取的点的位数的异或和大的胜利。看似给的数据很多,实际上边是完全用不到的。输入时对所有权值求异或和,如果异或和为0说明所有值相等,两个人最后一定平局,输出D即可,在不为零的情况下,选取异或和最高位为1的那一位,不难的出一定有奇数个这一位为1的权值,只要Q先拿走一个这样的点,那么剩下的在T拿走后异或值一定为0,肯定是Q胜利,所以得到很简洁的代码。顺便心疼T,怎么也赢不了。

#include<bits/stdc++.h>
using namespace std;
int main()
{int T;scanf("%d",&T);while(T--){int a,t;scanf("%d",&a);int ans=0;for(int i=0;i<a;i++){scanf("%d",&t);ans^=t;}for(int i=;i<a-1;i++)scanf("%d%d",&t,&t);if(ans==0) printf("D\n");else printf("Q\n");}return 0;
}

Problem F. Grab The Tree博弈相关推荐

  1. 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...

  2. Problem F. Grab The Tree HDU - 6324(树形dp+博弈)

    Little Q and Little T are playing a game on a tree. There are nn vertices on the tree, labeled by 1, ...

  3. Problem F: 结构体--学生信息排序

    Problem F: 结构体–学生信息排序 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 378 Solved: 192 [Submit][Status ...

  4. Problem F: Matrix Problem (III) : Array Practice Time Limit: 1 Sec Memory Limit: 4 MB Submit: 8787

    Problem F: Matrix Problem (III) : Array Practice Time Limit: 1 Sec  Memory Limit: 4 MB Submit: 8787  ...

  5. F - LIS on Tree【二分OR权值线段树】

    传送门 atcoder F - LIS on Tree 题意 给定一颗树,求节点111到各个节点路径上的最长上升子序列的长度 分析 之前只知道对序列进行二分nlognnlognnlogn的做法 给定一 ...

  6. Problem F: 凹凸四边形

    Problem F: 凹凸四边形 Description 四边形分为凸四边形和凹四边形,如下图,图1为凸四边形,图2为凹四边形. 按照连边顺序给出四边形的四个顶点坐标,判断该四边形是凹四边形还是凸四边 ...

  7. Problem F: 计票

    Problem F: 计票 Description 美国总统大选终于拉开了正式帷幕,大家都预计希拉里会获胜.各州的统计结果陆续出来了,你能帮忙统计下总得票吗? Input 多组测试数据,每组先输入一个 ...

  8. Problem F: 一天中的第几秒

    实验4 Problem F: 一天中的第几秒 Description 一天24小时,每小时60分钟,每分钟60秒.一天共有86400秒. 0点0分0秒是每天的第1秒: 0点0分1秒是每天的第2秒: 0 ...

  9. Problem F. 洗衣服

    Problem F. 洗衣服 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) T ...

最新文章

  1. 【重置版】Android studio高效开发的秘密
  2. i18n java_Java国际化(i18n) Locale类详细示例
  3. vue-axios 安装和应用
  4. 在MySQL中保存Java对象_java对象储存到数据库
  5. SQL Server 2005 Compact Edition 程序设计与性能优化
  6. base cap 分布式_干货分享:基于本地消息表的分布式事务解决方案总结
  7. Elasticsearch 7.7.0 基本操作-基于 CMD 命令行
  8. stylelint 规则
  9. PowerDesigner在生成SQL时报错Generation aborted due to errors detected during the verification of the mod
  10. Vue路由及路由守卫
  11. 关于黑马JavaWeb教程注册登录案例报错
  12. OpenCV3.0+VS2015+Win7x64开发环境搭建报错找不到gdi32.lib、opencv_world300d.dll
  13. 【Shader特效10】体积雾特效的使用
  14. 基于SSM的医院医疗管理系统的设计与实现
  15. jquery循环创建div
  16. HTML5+CSS3小实例:手风琴式加载动画
  17. NMAP——如何使用
  18. 【ICML 2015迁移学习论文阅读】Unsupervised Domain Adaptation by Backpropagation (DANN) 无监督领域自适应
  19. 思岚科技即将亮相2019上交会 展示机器人自主行走背后的技术
  20. PowerPC PPC460-S MMU(三 Access Control)

热门文章

  1. 把数据库中的数据制作成Excel数据
  2. struts2值栈分析
  3. Unix domain socket IPC
  4. 聊聊.net 程序设计——命名规范(上)
  5. 懒惰的人有福了——VS代码段编辑器SnippetEditor 可对vs所有代码段进行编辑和创建包括C#\J#\VB.NET等...
  6. 全局变量求平均分最高分最低分_打分函数trimmean,去掉最高最低分求平均分,用它就对了...
  7. cross apply
  8. (转)python中的参数:*args和**kwargs
  9. CURL 错误码 中文翻译
  10. asp.net 学习交流群 130017551