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 ...
随机推荐
- https://www.luogu.org/blog/An-Amazing-Blog/mu-bi-wu-si-fan-yan-ji-ge-ji-miao-di-dong-xi
https://www.luogu.org/blog/An-Amazing-Blog/mu-bi-wu-si-fan-yan-ji-ge-ji-miao-di-dong-xi
- 用AntDeploy如何更新Agent
AntDeploy AntDeploy是一款开源的一键发布部署工具,目的是代替重复性的发布动作,提高部署效率 1.一键部署iis 2.一键部署windows服务 3.一键部署到Docker 4.支持增 ...
- Python 教程资源
1.廖雪峰的官方网站 http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386 ...
- Throwing Dice LightOJ - 1064 || (勉强能用的)分数类
Throwing Dice LightOJ - 1064 方法: 设ans[i][j]表示i个骰子点数恰好为j的概率.那么ans[1][1]到ans[1][6]都为1/6. 显然,$ans[i][j] ...
- Four Segments CodeForces - 846C
题目 题意:sum(l,r)表示数列a中索引为l到r-1(都包含)的数之和(如果l==r则为0).给出数列a,求合适的delim0, delim1, delim2,使res = sum(0, deli ...
- 优先队列 POJ 2431 Expedition
题目传送门 题意:一辆卡车要行驶L长度,初始有P油,每行驶一个单位长度消耗一单位油.有n个加油站可以加油,问最少加油几次才能行驶L长度,如果不能输出-1 分析:按照挑战书的解法,每走到一个加油站相当于 ...
- Reduce实现
Reduce实现 参考 第一版 Array.prototype.fakeReduce = function (fn, base) { // this 指向原数组 // 拷贝数据, 更改指针方向 var ...
- Netbeans自定义折叠代码
只需要在模块开始注释以//<editor-fold>开始, 在模块结束行以 //</editor-fold>结束即可 Can I Create Custom Code Fold ...
- iOS7改变状态栏文字颜色
1在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO2 在需要改变状态栏颜色的 AppDelegate中在 didFinishLaun ...
- 多个版本数据库在在一台数据库上lib 的切换问题。
lib 的切换问题. 现象: /home/dbmon >sqlplus / as sysdba/usr/lib/hpux64/dld.so: Unsatisfied data symbol ' ...