Problem F. Grab The Tree HDU - 6324
题意:
给出一棵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的更多相关文章
- 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 ...
- HDU 6324.Problem F. Grab The Tree-博弈(思维) (2018 Multi-University Training Contest 3 1006)
6324.Problem F. Grab The Tree 题目看着好难,但是题解说的很简单,写出来也很简单.能想出来就是简单的,想不出来就难(讲道理,就算是1+1的题目,看不出来就是难的啊). 和后 ...
- 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 ...
- Problem: Query on the tree(二分+划分树)
题目链接: Problem: Query on the tree Time limit: 1s Mem limit: 64 MB Problem Description There ...
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- 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 ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- 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 ...
随机推荐
- matlab做聚类分析
说明:如果是要用matlab做kmeans聚类分析,直接使用函数kmeans即可.使用方法:kmeans(输入矩阵,分类个数k). 转载一: MATLAB提供了两种方法进行聚类分析: 1.利用 clu ...
- openwrt中在软件包中定义PKG_INSTALL将会发生什么?
答: 将会使用默认软件包安装方式,相关代码如下 . 在include/package.mk中: Build/Install=$(if $(PKG_INSTALL),$(call Build/Insta ...
- 在fedora23中安装virtualbox, 然后实现虚拟机irtualbox 或者 vmware 下的xp操作系统
参考: http://blog.csdn.net/statdm/article/details/7756788 参考: http://www.cnblogs.com/fengbohello/p/488 ...
- SpringBoot 使用Sharding-JDBC进行分库分表及其分布式ID的生成
为解决关系型数据库面对海量数据由于数据量过大而导致的性能问题时,将数据进行分片是行之有效的解决方案,而将集中于单一节点的数据拆分并分别存储到多个数据库或表,称为分库分表. 分库可以有效分散高并发量,分 ...
- 【分布式事务】spring cloud集成lcn解决分布式事务
参考地址:https://blog.csdn.net/u010882691/article/details/82256587 参考地址:https://blog.csdn.net/oyh1203/ar ...
- SSM到Spring Boot从零开发校园商铺平台
项目目的 特别 由于准备春招,所以希望各位看客方便的话,能去github上面帮我Star一下项目 https://github.com/Draymonders/Campus-Shop emmm, 已经 ...
- vue项目从引入vue.js 改为使用vue-cil (webpack)时修改的一些内容
在元素属性中不要写js关键字,会报使用关键字的错如@click='if(){}else{}', if-else 语句可以使用三元表达式或短路运算符来实现 v-for 不写:key 会有警告 ,使用: ...
- (zhuan) 自然语言处理中的Attention Model:是什么及为什么
自然语言处理中的Attention Model:是什么及为什么 2017-07-13 张俊林 待字闺中 要是关注深度学习在自然语言处理方面的研究进展,我相信你一定听说过Attention Model( ...
- Ubuntu关机时间过长,总是停在logo界面
有时候我们总能遇到ubuntu关机的时候卡住,无法关机,一查看发现是" a stop job is running..." 然后后面接着一串等待时间. 这时候我们需要修改一下sys ...
- webpack用 babel将ES6转译ES5
webpack webpack.config.js配置文件 module.exports = { entry: './es6.js', // 入口文件路径 output: { filename: &q ...