【HDU 3590】 PP and QQ (博弈-Anti-SG游戏,SJ定理,树上删边游戏)
PP and QQ
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 510 Accepted Submission(s): 256Problem DescriptionPP 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.InputThe 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.OutputFor each test case, output the name of the winner.Sample Input2
2
1 2
2
1 2
1
2
1 2Sample OutputPPAuthoralpc27
#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定理,树上删边游戏)的更多相关文章
- hdu 3590 PP and QQ 博弈论
思路: 在贾志豪神牛的论文 里,这两种游戏都有 其中树的删边游戏:叶子节点的SG值为0:中间节点的SG值为它的所有子节点的SG值加1 后的异或和. ANTI-SG:先手必胜当且仅当:(1)游戏的SG函 ...
- hdu 3590 PP and QQ
知识储备: Anti-SG 游戏和 SJ 定理 [定义](anti-nim 游戏) 桌子上有 N 堆石子,游戏者轮流取石子. 每次只能从一堆中取出任意数目的石子,但不能不取. 取走最后一 ...
- HDU 3970 Paint Chain (博弈,SG函数)
Paint Chain Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 简单易懂的博弈论讲解(巴什博弈、尼姆博弈、威佐夫博弈、斐波那契博弈、SG定理)
博弈论入门: 巴什博弈: 两个顶尖聪明的人在玩游戏,有一堆$n$个石子,每次每个人能取$[1,m]$个石子,不能拿的人输,请问先手与后手谁必败? 我们分类讨论一下这个问题: 当$n\le m$时,这时 ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- 【BZOJ 2688】 2688: Green Hackenbush (概率DP+博弈-树上删边)
2688: Green Hackenbush Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 42 Solved: 16 Description ...
- HDU 1524 树上无环博弈 暴力SG
一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...
- 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)运算 ...
- 博弈之——SG模板
很久没搞博弈了.先来写个模板: 现在我们来研究一个看上去似乎更为一般的游戏:给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移动者判负.事实上,这个游戏可以 ...
随机推荐
- django模板中的自定义过滤器
(1)在APP下创建templatetags文件夹,与Models.py.views.py等同级,templatetags文件夹下添加__init__.py文件,可为空,再添加一个模块文件,例如cpt ...
- Java基础-SSM之mybatis一对一外键关联
Java基础-SSM之mybatis一对一外键关联 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.准备测试环境(创建数据库表) 1>.创建husbandsfk和wife ...
- CSS function--(来自网易)
/* function */ .f-cb:after,.f-cbli li:after{;overflow:hidden;content:".";} .f-cb,.f-cbli l ...
- 【两分钟视频教程】如何使用myeclipse在mac本机运行iOS配套的服务器
如何使用myeclipse在mac本机运行iOS配套的服务器
- Ubuntu 查看CPU温度
按照这篇文章: http://www.webupd8.org/2014/06/psensor-updated-with-option-to-display.html
- 洛谷 P4128: bzoj 1815: [SHOI2006]有色图
题目传送门:洛谷 P4128. 计数好题,原来是 13 年前就出现了经典套路啊.这题在当年应该很难吧. 题意简述: \(n\) 个点的完全图,点没有颜色,边有 \(m\) 种颜色,问本质不同的图的数量 ...
- 【C++】wchar、char格式化符输出
VC.BCB.MinGW Linux下的GCC.C99标准 printf wprintf printf wprintf s char wchar_t char S wchar_t char * hs ...
- .NET C# Tostring format 格式化字符串
一.数值型 formatCode 是可选的格式化代码字符串.必须用“{”和“}”将格式与其他字符分开.如果恰好在格式中也要使用大括号,可以用连续的两个大括号表示一个大括号,即: “{{”或者“}}”. ...
- centos6.5环境DNS-本地DNS主从服务器bind的搭建
centos6.5环境DNS-本地DNS主从服务器bind的搭建 在上一篇博客中我已经搭建好了一个本地DNS服务器,能够实现正向反向解析,那么我们只需要加入一台从DNS服务器即可完成,我们来开始配置主 ...
- bootstrap 引用注意事项
2014年6月8日 13:35:31 bootstrap 提供了cdn服务,在引用css,js的时候注意先后顺序,firebug就不会报错 <script src="http://cd ...

