Description
Input
Input data first input two integer n,m, indicating the length of the maze. Next n lines, m characters per line, describe the maze.
Output
If the small AA can win the game, then output a line of "win", then output all the starting positions that can win the game, output each line in order of precedence, or output a line "lose" (without quotation marks).
Sample INPUT3 3
.##
...
#. #Sample Outputwin
2 3
3 2HINT
For 100% of the data, there is 1≤n,m≤100. For 30% of the data, there is 1≤n,m≤5.
Positive solution: Binary graph + game theory.
First of all, we can dye this grid graph in black and white, adjacent points with edges, into a binary graph.
Small $aa$ is a low-down, to win the necessary and sufficient conditions is the starting point is not necessarily in the maximum match.
If the starting point is not in the maximum match, then the point adjacent to the starting point must be in the maximum match.
Small $yy$ move, small $aa$ can always move to the current point of the match point, so small $aa$ win.
Determine whether a point must be in the maximum match can be deleted from this point, and then see whether the maximum match changes.
But if we do this here, it will be $t$, so we consider other ways.
We first ask for the maximum match and then find the point that does not match, it must be the legal starting point.
From this point on the search, directly find the adjacent points of the match point, then this match point is certainly a legitimate point.
Then search all the way to find out all the possible solutions.
1#include <bits/stdc++.h>2 #defineIl inline3 #defineRG Register4 #definell Long Long5 #definePOS (x, y) ((x-1) *m+ (y))6 #defineN (100005)7 8 using namespacestd;9 Ten structedge{intNt,to;} G[n]; One A Const intd1[4]={1,0,-1,0}; - Const intd2[4]={0,1,0,-1}; - the inthead[n],can[n],vis[n],lk[n],mp[ the][ the],ok,n,m,num,cnt,ans; - -Ilintgi () { -Rgintx=0, q=1; RgCharCh=GetChar (); + while((ch<'0'|| Ch>'9') && ch!='-') ch=GetChar (); - if(ch=='-') q=-1, ch=GetChar (); + while(ch>='0'&& ch<='9') x=x*Ten+ch- -, ch=GetChar (); A returnq*x; at } - -IlCharGC () { -RgCharCh=GetChar (); - while(ch!='.'&& ch!='#') Ch=getchar ();returnch; - } in -IlvoidInsert (RGint fromRgintTo ) { toG[++num]= (Edge) {head[ from],to},head[ from]=num;return; + } - theIlintDFS (RGintx) { *vis[x]=CNT; $ for(RGintI=head[x],v;i;i=G[i].nt) {Panax Notoginsengv=g[i].to;if(vis[v]==cnt)Continue; vis[v]=CNT; - if(!lk[v] | | DFS (LK[V)) {lk[x]=v,lk[v]=x;return 1; } the } + return 0; A } the +IlvoidFind (RGintx) { - if(vis[x]==cnt)return; vis[x]=cnt,can[x]=1; $ for(RGintI=head[x];i;i=G[i].nt) $ if(vis[lk[g[i].to]]!=cnt) find (lk[g[i].to]); - return; - } the - intMain () {Wuyi #ifndef Online_judge theFreopen ("game.in","R", stdin); -Freopen ("Game.out","W", stdout); Wu #endif -N=gi (), m=gi (); About for(RGintI=1; i<=n;++i) $ for(RGintj=1; j<=m;++j) MP[I][J]=GC () = ='.'; - for(RGintI=1; i<=n;++i) - for(RGintj=1; j<=m;++j) { - if(!mp[i][j])Continue; A for(RGintk=0,x,y;k<2;++k) { +X=I+D1[K],Y=J+D2[K];if(X>n | | y>m | |!mp[x][y])Continue; the Insert (POS ( i,j), POS (x, y)), insert (POS (x, y), POS (i,j)); - } $ } the for(RGintI=1; i<=n;++i) the for(RGintj=1; j<=m;++j) the if(Mp[i][j] &&!lk[pos (i,j)) + +Cnt,dfs (POS (i,j)); the for(RGintI=1, x,y;i<=n*m;++i) { -x= (I-1)/m+1, y= (i-1)%m+1; in if(Mp[x][y] &&!lk[i]) + +Cnt,find (i); the } the for(RGintI=1, x,y;i<=n*m;++i) { About if(!can[i])Continue; thex= (I-1)/m+1, y= (i-1)%m+1; the if(!ok) ok=1, Puts ("WIN"); theprintf"%d%d\n", x, y); + } - if(!ok) puts ("lose");return 0; the}
bzoj1443 [JSOI2009] Game games