题意:
给出一棵n个节点的树,每个节点有一个权值,Q和T玩游戏,Q先选一些不相邻的节点,T选剩下的节点,每个人的分数是所选节点的权值的异或和,权值大的胜出,问胜出的是谁。

题解:

  话说,这题后面的边跟解的过程半毛钱关系没有,但是自己就是想不到,这博弈。。。

设sum为所有点权的异或和,A为先手得分,B为后手得分。

  若sum=0,则A=B,故无论如何都是平局。

  否则考虑sum二进制下最高的1所在那位,一定有奇数个点那一位为1。若先手拿走任意一个那一位为1的点,则B该位为0,故先手必胜。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,ans=;
scanf("%d",&n);
for(int i=;i<=n;i++){
int a;
scanf("%d",&a);
ans^=a;
}
for(int i=;i<n-;i++){
int u,v;
scanf("%d%d",&u,&v);
}
if(ans==) cout<<"D"<<endl;
else cout<<"Q"<<endl;
}
}

Problem F. Grab The Tree HDU - 6324的更多相关文章

  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. HDU 6324.Problem F. Grab The Tree-博弈(思维) (2018 Multi-University Training Contest 3 1006)

    6324.Problem F. Grab The Tree 题目看着好难,但是题解说的很简单,写出来也很简单.能想出来就是简单的,想不出来就难(讲道理,就算是1+1的题目,看不出来就是难的啊). 和后 ...

  3. 2018HDU多校训练-3-Problem F. Grab The Tree

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

  4. Problem: Query on the tree(二分+划分树)

    题目链接: Problem: Query on the tree Time limit: 1s     Mem limit: 64 MB      Problem Description There ...

  5. 实验12:Problem F: 求平均年龄

    Home Web Board ProblemSet Standing Status Statistics   Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...

  6. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  7. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  8. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  9. Codeforces Gym 100286F Problem F. Fibonacci System 数位DP

    Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

随机推荐

  1. CentOS 源码编译安装 Python3

    准备 yum -y install wget gcc make libffi-devel zlib-devel readline-devel bzip2-devel ncurses-devel sql ...

  2. 4698: Sdoi2008 Sandy的卡片

    前言 总之这个东西说起来很麻烦就是了, 思路 差分合并+后缀数组+二分(dddl) 类似于那个bzoj1031的复制子串和那个poj1743的差分 来看个例子 3 5 1 2 3 4 5 4 1 1 ...

  3. Many Website Of WallPaper

    我在这里给大家推荐几个不错的壁纸网站 毕竟一张赏心悦目的壁纸能让你的工作效率提高不少 注意前方高能 一大波网站即将来袭 一系列 如你所见 alphacoders wallpaperdj Wallhav ...

  4. Directional RNA-seq data -which parameters to choose?

    Directional RNA-seq data -which parameters to choose? REF: https://chipster.csc.fi/manual/library-ty ...

  5. 【OData】使用Odata获取数据之后再次获取可能得不到最新的数据问题记录

    工作上遇到个问题是关于系统后台数据库更新了某数据后, 前台界面刷新显示的不是最新的数据.但是大约10分后再次刷新就能显示新的数据,或者重启IIS等web server host. 最开始认为可能是因为 ...

  6. Docker6之Network containers

    how to network your containers. Launch a container on the default network Docker includes support fo ...

  7. 批处理bat标准化获取当前系统日期的几种方法,补0

    首先有两个推荐的方案. 一: for /f "tokens=2 delims==" %%a in ('wmic path win32_operatingsystem get Loc ...

  8. 远程主动读取数据 RFC_READ_TABLE

    IF IM_UDATE1 <> IM_UDATE2."get data from bw     CLEAR IT_SEL_TAB.     IT_SEL_TAB = '( /BI ...

  9. 【UOJ#196】【BZOJ4574】[Zjoi2016]线段树

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4574 http://uoj.ac/problem/196 考虑数字随机并且值域够大,我们 ...

  10. Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和

    D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...