PP and QQ

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 510    Accepted Submission(s): 256

Problem Description
PP and QQ were playing games at Christmas Eve. They drew some Christmas trees on a paper:

Then they took turns to cut a branch of a tree, and removed the part of the tree which had already not connected with the root. A step shows as follows:

PP always moved first. 
PP and QQ took turns (PP was always the first person to move), to cut an edge in the graph, and removed the part of the tree that no longer connected to the root. The person who cannot make a move won the game. 
Your job is to decide who will finally win the game if both of them use the best strategy. 

Input
The input file contains multiply test cases.
The first line of each test case is an integer N (N<100), which represents the number of sub-trees. The following lines show the structure of the trees. The first line of the description of a tree is the number of the nodes m (m<100). The nodes of a tree are numbered from 1 to m. Each of following lines contains 2 integers a and b representing an edge <a, b>. Node 1 is always the root. 
Output
For each test case, output the name of the winner.
Sample Input
2
2
1 2
2
1 2
1
2
1 2
Sample Output
PP
QQ
Author
alpc27
 
 
【分析】
  首先是一个树上删边游戏。
  就是子树的sg+1的乘积啦。。不说了
  然后是Anti-SG游戏,有SJ定理,具体看jzh的论文吧。
  

  证明的话,只需说明:
  最后的状态符合这个定理。
  必胜态一定能到一个必败态。
  必败态到的都是必胜态 即可、
  这个自己YY瞎搞一下就能证明了。
 
  就是这样了。
 
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 110 struct node
{
int x,y,next;
}t[Maxn*];
int first[Maxn],len; void ins(int x,int y)
{
t[++len].x=x;t[len].y=y;
t[len].next=first[x];first[x]=len;
} int dfs(int x,int f)
{
int ans=;
for(int i=first[x];i;i=t[i].next) if(t[i].y!=f)
{
ans^=(dfs(t[i].y,t[i].x)+);
}
return ans;
} int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
int ans=;
bool ok=;
while(T--)
{
int n;
scanf("%d",&n);
len=;
for(int i=;i<=n;i++) first[i]=;
for(int i=;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
ins(x,y);ins(y,x);
}
int nw=dfs(,);
if(nw>) ok=;ans^=nw;
}
if((!ans&&!ok)||(ans&&ok)) printf("PP\n");
else printf("QQ\n");
}
return ;
}

2017-04-27 17:11:55

【HDU 3590】 PP and QQ (博弈-Anti-SG游戏,SJ定理,树上删边游戏)的更多相关文章

  1. hdu 3590 PP and QQ 博弈论

    思路: 在贾志豪神牛的论文 里,这两种游戏都有 其中树的删边游戏:叶子节点的SG值为0:中间节点的SG值为它的所有子节点的SG值加1 后的异或和. ANTI-SG:先手必胜当且仅当:(1)游戏的SG函 ...

  2. hdu 3590 PP and QQ

    知识储备: Anti-SG 游戏和 SJ 定理  [定义](anti-nim 游戏)  桌子上有 N 堆石子,游戏者轮流取石子.  每次只能从一堆中取出任意数目的石子,但不能不取.  取走最后一 ...

  3. HDU 3970 Paint Chain (博弈,SG函数)

    Paint Chain Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. 简单易懂的博弈论讲解(巴什博弈、尼姆博弈、威佐夫博弈、斐波那契博弈、SG定理)

    博弈论入门: 巴什博弈: 两个顶尖聪明的人在玩游戏,有一堆$n$个石子,每次每个人能取$[1,m]$个石子,不能拿的人输,请问先手与后手谁必败? 我们分类讨论一下这个问题: 当$n\le m$时,这时 ...

  5. HDU 3094 树上删边 NIM变形

    基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...

  6. 【BZOJ 2688】 2688: Green Hackenbush (概率DP+博弈-树上删边)

    2688: Green Hackenbush Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 42  Solved: 16 Description   ...

  7. HDU 1524 树上无环博弈 暴力SG

    一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...

  8. HDU 1848 Fibonacci again and again【SG函数】

    对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...

  9. 博弈之——SG模板

    很久没搞博弈了.先来写个模板: 现在我们来研究一个看上去似乎更为一般的游戏:给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移动者判负.事实上,这个游戏可以 ...

随机推荐

  1. MySQL存储引擎对比

    MySQL存储引擎对比 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL的存储引擎 大家应该知道MySQL的存储引擎应该是表级别的概念,因为我们无法再创建databas ...

  2. Python内置函数之匿名(lambda)函数

    Python内置函数之匿名(lambda)函数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.匿名函数 #!/usr/bin/env python #_*_coding:utf ...

  3. jdk1.8中获取项目绝对路径和项目路径

    request.getSession().getServletContext().getRealPath("")  获取项目的绝对路径,含着项目的名称. request.getSe ...

  4. windows服务写完之后怎么让它跑起来

    当然你可以在命令框里面自己去手动的敲代码,也可以写一个.bat文件一劳永逸......这里我就介绍写.bat文件的方法 就是上图所示的三个东东啦,有了这三个东东,把他们拖到你windows服务的deb ...

  5. oracle 工作笔记,不定期更新

    此博客为工作时,所见技术问题的解决方案笔记,欢迎大家转载,转载请注明出处,谢谢~ 更新时间: 2017-07-12 1. clob字段值读取时,借用extractvalue或extract函数读取节点 ...

  6. Solr记录-solr介绍及配置

    Solr是一个开源搜索平台,用于构建搜索应用程序. 它建立在Lucene(全文搜索引擎)之上. Solr是企业级的,快速的和高度可扩展的. 使用Solr构建的应用程序非常复杂,可提供高性能. 为了在C ...

  7. eclipse 下编译c++

    下载jdk 下载eclipse for c++ 版本 下载mingw ps:show project types... 这个选项不要打钩

  8. AngularJS入门基础——作用域

    作用域$scope是构成AngularJS应用的核心基础,在整个框架中都被广泛使用,因此了解它是非常重要的. $scope对像是定义应用业务逻辑,控制器方法和视图属性的地方.作用域是视图和控制器之间的 ...

  9. HTML5 移动开发(移动设备检测及对HTML5的支持)

    1.如何选择要使用的特性以及所面向的浏览器 2.哪些浏览器支持HTML5 3.如何检测是否支持HTML5 4.如何开发贷容错性的Web应用程序 5.CSS3媒体查询如何增强检测脚本   使用HTML5 ...

  10. 第7月第19天 swift on linux

    1. https://github.com/iachievedit/moreswift http://dev.iachieved.it/iachievedit/more-swift-on-linux/ ...