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 ...
随机推荐
- Vistual Studio Code配置
目录 查看版本,帮助: 修改vscode的扩展目录: 用户和工作区设置 用户设置的文件保存在如下目录: 所以有三种方式更改默认的设置: vscode同步配置: vscode启动launch.json配 ...
- docker-compose安装与部署项目
安装: 1.curl安装慢的问题 解决:改用pip安装,需要先安装pip相关,参照: https://www.cnblogs.com/YatHo/p/7815400.html 2.pip安装依赖库re ...
- How to resize slide dimensions without resizing any objects on the slide?
IF you are competent to unzip the pptx file and modify the XML it can be done, the slide size will c ...
- [小问题笔记(九)] SQL语句Not IN 效率低,用 NOT EXISTS试试
项目中遇到这么个情况: t1表 和 t2表 都是150w条数据,600M的样子,都不算大. 但是这样一句查询 ↓ select * from t1 where phone not in (selec ...
- 【Cucumber】【命令行】
知识点 参考:https://www.cnblogs.com/worklog/p/5253297.html cucumber的命令行选项 首先查看命令行选项.和其它命令行工具一样,cucumber提供 ...
- ros 节点关闭后重启
加入参数 respawn="true"
- Hibernate的查询功能
1.Query对象 1.使用Query对象,不需要写sql语句,但是写hql语句 (1)hql:hibernate query language,提供查询语言,这个hql语言和普通sql语句相似 (2 ...
- MySQL数据分组Group By 和 Having
现有以下的学生信息表: 若果现在想计算每个班的平均年龄,使用where的操作如下: SELECT Cno AS 班级, AVG(Sage) AS 平均年龄 FROM stu ; 这样的话,有多少个班就 ...
- stop 用法
1. stop 文档 $(selector).stop(stopAll,goToEnd) stopAll 可选.规定是否停止被选元素的所有加入队列的动画.goToEnd 可选.规定是否允许完成当前的动 ...
- d3 .each()
d3.select("xxx") .each(function (d) { //this表示当前element 而 d表示绑定的数据 something(this); }); 注意 ...