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 ...
随机推荐
- bzoj 1433: [ZJOI2009]假期的宿舍【匈牙利算法】
i能睡j床的连边(i,j),跑最大匹配或者最大流,然后看看人数能不能对上总数即可 #include<iostream> #include<cstdio> #include< ...
- 笔记:JavaScript闭包
闭包 闭包是一种保护私有变量的机制,在函数执行时形成私有的作用域,保护里面的私有变量不受外界干扰.直观的说就是形成一个不销毁的栈环境. 对于闭包,当外部函数返回之后,内部函数依然可以访问外部函数的变量 ...
- (六)SpringBoot整合Swagger2框架
一:什么是Swagger Swagger是一款通过我们添加的注解来对方法进行说明,来自动生成项目的在线api接口文档的web服务. 二:添加Swagger2依赖 <dependency> ...
- Vue-CLI3详解
vue-cli3快速开始 node 安装,略. webpack 安装webpack npm install webpack webpack-cli -g 查看版本 webpack -v vue-cli ...
- spring @InitBinder
/** * 将字符串日期转化为Date类型 * @param binder */ @InitBinder protected void initBinder(WebDataBinder binder) ...
- JavaScript--数组常用方法总结
JavaScript--数组常用方法总结 测试模板: var arr = ["a", "b", "c", "d", &q ...
- android动画(2)自定义动画
public class CustomAnimation extends Animation { // 这个方法可以获得动画view的width,height,以及它父view的width @Over ...
- windows session 管理
Killing an Oracle process from inside Oracle I had a following situation few days ago – I was runnin ...
- SpringCloud开发学习总结(七)—— 声明式服务调用Feign(三)
Feign中的Ribbon配置 由于Spring Cloud Feign的客户端负载均衡是通过Spring Cloud Ribbon实现的,所以我们可以直接通过配置Ribbon客户端的方式来自定义各个 ...
- 517 Super Washing Machines 超级洗衣机
详见:https://leetcode.com/problems/super-washing-machines/description/ C++: class Solution { public: i ...