博弈论
贾志豪论文上的题目……题解请看论文
Orz了一下Hzwer
1 Source Code 2 Problem: 3710 User: sdfzyhy 3 Memory: 716K Time: 0MS 4 Language: G++ Result: Accepted 5 6 Source Code 7 8 //POJ 3710 9 #include<cstdio> 10 #include<cstring> 11 #include<iostream> 12 #define F(i,j,n) for(int i=j;i<=n;++i) 13 int getint(){ 14 int v=0,sign=1; char ch=getchar(); 15 while(!isdigit(ch)) {if(ch==‘-‘) sign=-1; ch=getchar();} 16 while(isdigit(ch)) {v=v*10+ch-‘0‘; ch=getchar();} 17 return v*sign; 18 } 19 const int N=1010,INF=~0u>>2; 20 const double eps=1e-8; 21 /*******************template********************/ 22 int to[N],next[N],head[N],cnt,s[N],top; 23 bool vis[N],ve[N],w[N]; 24 void add(int x,int y){ 25 to[++cnt]=y; next[cnt]=head[x]; head[x]=cnt; 26 to[++cnt]=x; next[cnt]=head[y]; head[y]=cnt; 27 } 28 int dfs(int x){ 29 vis[x]=1; 30 int ans=0; 31 s[++top]=x; 32 for(int i=head[x];i;i=next[i]) 33 if(!ve[i]){ 34 ve[i]=ve[i^1]=1; 35 int temp; 36 if (!vis[to[i]]) temp=dfs(to[i])+1; 37 else{ 38 int q=s[top--]; 39 while(q!=to[i]){ 40 w[q]=1;//环上节点标记 41 q=s[top--]; 42 } 43 ++top; 44 return 1; 45 }//缩环 46 if(w[to[i]]) ans^=temp%2; 47 else ans^=temp; 48 } 49 return ans; 50 } 51 void clear(){ 52 memset(head,0,sizeof head); 53 memset(next,0,sizeof next); 54 memset(vis,0,sizeof vis); 55 memset(ve,0,sizeof ve); 56 memset(w,0,sizeof w); 57 top=0; cnt=1; 58 } 59 int main(){ 60 int T,n,m,x,y; 61 while(scanf("%d",&T)!=EOF){ 62 int ans=0; 63 F(i,1,T){ 64 clear(); 65 n=getint(); m=getint(); 66 F(i,1,m){ 67 x=getint(); y=getint(); 68 add(x,y); 69 } 70 ans^=dfs(1); 71 } 72 puts(ans ? "Sally" : "Harry"); 73 } 74 return 0; 75 }
时间: 2024-11-06 18:21:46