poj3710 Christmas Game
题解:
树上删边。
对于奇数长度的环,可以看做一条边。
对于偶数长度的环,可以看做什么都没有。
没有特别好的解释……
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
template<typename T>
inline void read(T&x)
{
T f = ,c = ;char ch = getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){c=c*+ch-'';ch=getchar();}
x = f*c;
}
int T,n,m,hed[N],cnt;
struct EG
{
int to,nxt;
}e[*N];
void ae(int f,int t)
{
e[++cnt].to = t;
e[cnt].nxt = hed[f];
hed[f] = cnt;
}
bool vis[N],cir[N],ban[*N];
int sta[N],tl;
int dfs(int u)
{
vis[u]=;
sta[++tl]=u;
int ret = ;
for(int j=hed[u];~j;j=e[j].nxt)
{
if(ban[j])continue;
ban[j]=ban[j^]=;
int to = e[j].to;
int now;
if(!vis[to])now=(dfs(to)+);
else
{
int q = sta[tl--];
while(q!=to)
{
cir[q]=;
q=sta[tl--];
}
tl++;
return ;
}
if(cir[to])ret^=(now&);
else ret^=now;
}
return ret;
}
int main()
{
while(scanf("%d",&T)>)
{
// read(T);
int ans=;
while(T--)
{
memset(hed,-,sizeof(hed));
memset(cir,,sizeof(cir));
memset(vis,,sizeof(vis));
memset(ban,,sizeof(ban));
cnt=-;tl=;
read(n),read(m);
for(int f,t,i=;i<=m;i++)
{
read(f),read(t);
ae(f,t),ae(t,f);
}
int now = dfs();
ans^=now;
}
puts(ans?"Sally":"Harry");
}
return ;
}
poj3710 Christmas Game的更多相关文章
- POJ3710 Christmas Game 博弈论 sg函数 树的删边游戏
http://poj.org/problem?id=3710 叶子节点的 SG 值为0:中间节点的SG值为它的所有子节点的SG值加1后的异或和. 偶环可以视作一个点,奇环视为一条边(连了两个点). 这 ...
- 博弈论BOSS
基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...
- 【Mark】博弈类题目小结(HDU,POJ,ZOJ)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...
- 【POJ3710】Christmas Game (博弈-树上的删边问题)
[题目] Description Harry and Sally were playing games at Christmas Eve. They drew some Christmas trees ...
- Christmas Trees, Promises和Event Emitters
今天有同事问我下面这段代码是什么意思: var MyClass = function() { events.EventEmitter.call(this); // 这行是什么意思? }; util.i ...
- POJ3160 Father Christmas flymouse[强连通分量 缩点 DP]
Father Christmas flymouse Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 3241 Accep ...
- Father Christmas flymouse--POJ3160Tarjan
Father Christmas flymouse Time Limit: 1000MS Memory Limit: 131072K Description After retirement as c ...
- POJ3013 Big Christmas Tree[转换 最短路]
Big Christmas Tree Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 23387 Accepted: 5 ...
- poj 3013 Big Christmas Tree (最短路径Dijsktra) -- 第一次用优先队列写Dijsktra
http://poj.org/problem?id=3013 Big Christmas Tree Time Limit: 3000MS Memory Limit: 131072K Total S ...
随机推荐
- python多线程批量下载远程图片
python多线程使用场景:多线程采集, 以及性能测试等 . 数据库驱动类-简单封装下 mysqlDriver.py #!/usr/bin/python3 #-*- coding: utf-8 -*- ...
- 2019 年 Vue 学习路线图!
如果你是 Vue 开发新手,可能已经听过很多行话术语,比如单页面应用程序.异步组件.服务器端渲染,等等.你可能还听说过与 Vue 有关的一些工具和库,比如 Vuex.Webpack.Vue CLI 和 ...
- C++ 的输出格式
0 在C语言中很简单对输出的要求,然而在C++中有一丝的麻烦. 在下面的代码中所需要的是 #include<iostream> 基本输入/输出库 #include<iomanip&g ...
- visual studio各版本下载
软件包括以下几种: cn_visual_studio_2010_ultimate_x86_dvd_532347.part1.rar cn_visual_studio_2010_ultimate_x86 ...
- HDU - 6063 RXD and math
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6063 打表发现规律是n^k #include <iostream> #inc ...
- Apache Kylin的架构特性
不多说,直接上干货! http://kylin.apache.org/cn/ 可扩展的超快OLAP引擎,提供标准SQL查询接口 支持单机或集群部署,为减少在Hadoop上百亿规模数据查询延迟而设计: ...
- FFmpegUtil
这几天没事研究音频玩 比如 X配音app的配音功能 录一段 pcm或者wav格式的文件 替换mp4指定位置的音频刚开始卡在 pcm混合以及pcm指定位置插入.思路 一段段的视频进行切割 用到MP4Co ...
- re匹配语法-match、search和findall
1.re.match() 匹配第一个值 列表里的值可以有多个范围,有一个符合就可以. match只匹配第一个值,所以列表里的范围是第一个值得取值范围.如果第一个值被设定好且存在,那么列表的取值范围变为 ...
- poj3262 Protecting the Flowers
思路: 简单贪心,每次选择性价比最高的. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...
- UOJ#52. 【UR #4】元旦激光炮(交互)
题意 给出三个已经排好序的数组$a, b, c$ 在$100$次询问内找出第$k$小的元素 Sol 一种很显然的$log^2n$的做法:首先在$a$中二分,然后再$b,c$中二分.这样可以得到$60$ ...