【POJ】【3710】Christmas Game
博弈论
贾志豪论文上的题目……题解请看论文
Orz了一下Hzwer
Source Code
Problem: User: sdfzyhy
Memory: 716K Time: 0MS
Language: G++ Result: Accepted Source Code //POJ 3710
#include<cstdio>
#include<cstring>
#include<iostream>
#define F(i,j,n) for(int i=j;i<=n;++i)
int getint(){
int v=,sign=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') sign=-; ch=getchar();}
while(isdigit(ch)) {v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=,INF=~0u>>;
const double eps=1e-;
/*******************template********************/
int to[N],next[N],head[N],cnt,s[N],top;
bool vis[N],ve[N],w[N];
void add(int x,int y){
to[++cnt]=y; next[cnt]=head[x]; head[x]=cnt;
to[++cnt]=x; next[cnt]=head[y]; head[y]=cnt;
}
int dfs(int x){
vis[x]=;
int ans=;
s[++top]=x;
for(int i=head[x];i;i=next[i])
if(!ve[i]){
ve[i]=ve[i^]=;
int temp;
if (!vis[to[i]]) temp=dfs(to[i])+;
else{
int q=s[top--];
while(q!=to[i]){
w[q]=;//环上节点标记
q=s[top--];
}
++top;
return ;
}//缩环
if(w[to[i]]) ans^=temp%;
else ans^=temp;
}
return ans;
}
void clear(){
memset(head,,sizeof head);
memset(next,,sizeof next);
memset(vis,,sizeof vis);
memset(ve,,sizeof ve);
memset(w,,sizeof w);
top=; cnt=;
}
int main(){
int T,n,m,x,y;
while(scanf("%d",&T)!=EOF){
int ans=;
F(i,,T){
clear();
n=getint(); m=getint();
F(i,,m){
x=getint(); y=getint();
add(x,y);
}
ans^=dfs();
}
puts(ans ? "Sally" : "Harry");
}
return ;
}
【POJ】【3710】Christmas Game的更多相关文章
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- 【POJ 1459 power network】
不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...
- 【POJ 2728 Desert King】
Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...
- 【POJ 2976 Dropping tests】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...
- 【POJ 3080 Blue Jeans】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...
- 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)
1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- 【POJ 2823 Sliding Window】 单调队列
题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...
- 【POJ 2406 Power Strings】
Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
随机推荐
- 20141110--SQL视图
--------------------------视图--------------------- --视图是一个虚拟表,数据来自于原表,原表的数据改变,视图也会改变 select Student.S ...
- UI4_UIImageView
// // ViewController.m // UI4_UIImageView // // Created by zhangxueming on 15/7/1. // Copyright (c) ...
- JSLint notepad++使用
1.JSLint简介 JSLint定义了一组编码约定,这比ECMA定义的语言更为严格.这些编码约定汲取了多年来的丰富编码经验,并以一条年代久远的编程原则 作为宗旨:能做并不意味着应该做.JSLint会 ...
- idea基本
IntelliJ IDEA特色功能 IDEA所提倡的是智能编码,是减少程序员的工作,IDEA的特色功能有以下25点:智能的选取在很多时候我们要选取某个方法,或某个循环或想一步一步从一个变量到整个类慢慢 ...
- go开发环境配置
- 查看某个模块的Tables
在SE11 中 关于table的F4 help 有一个筛选条件是Package 同时由于不同的模块放在不同的Package中 很容易根据这个条件 获得某个模块的所有Tables 亲测有效 1 ...
- 卡通投掷游戏ios源码
卡通投掷游戏源码,一款基于cocos2d很有意思的卡通投掷游戏源码,使用重力感应摇动手机让猴子打转,然后点击屏幕任何地方将猴子抛出去,抛出去的过程中会收集星星,游戏的规则就是抛得越远越好,收集的星星最 ...
- linux 定时执行任务 crontab
欲编写定时任务访问网页和打开图片 原来写法为 #!/bin/bash #可以执行 echoecho "Hello" > dir/file.txt #不可以执行 xdg-ope ...
- Func 委托
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Informix 物联网应用示例(转)
相关概念 MQTT 是一个物联网传输协议,它被设计用于轻量级的发布/订阅式消息传输,旨在为低带宽和不稳定的网络环境中的物联网设备提供可靠的网络服务.MQTT 是专门针对物联网开发的轻量级传输协议.MQ ...