1443: [JSOI2009] Game games
Time Limit:10 Sec Memory limit:162 MB
submit:1334 solved:613
[Submit] [Status] [Discuss]
Descriptioninput
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 Input
3 3
.##
...
. Sample Output
WIN
2 3
3 2
HINT
For 100% of the data, there is 1≤n,m≤100. For 30% of the data, there is 1≤n,m≤5.
Exercises
Black and white dyeing, can go to the point of the edge, do a maximum match
found that if the initiator is placed on a non-matching point, there is no way to go, fail, or go to the matching point; if you go to the matching point, the initiator along the matching point go, there is no way to go, or go non-matching side, The next step must be a matching point .... have been so go down, found that the alternate road, because there is no augmented road, the end of the alternate road must be a matching side, there must be no way to go. At this point the winner will win the
Win point is the unmatched points in all the maximum matching scheme
Other points are required to defeat the point (equivalent to the initiator to go to the winning point, the back of the point that has to go, so will be defeated)
how to beg? The
finds that no match point starts, and after a non-matching edge, matching edge, the swap matching edge matches the non-matching edge, matching the legal and the maximum match unchanged. That is, we take the alternate path from each non-match point, and then all points connected by the match point are the answer (that is, the point of the same set as the starting point)
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < algorithm> #include <queue> #include <vector> #include <map> #include <string> #include < cmath> #include <sstream> #define MIN (A, B) ((a) < (b)? (a): (b) #define MAX (A, B) ((a) > (b)? (a): (b) #define ABS (a) ((a) < 0? ( -1 * (a)): (a)) Template<class t>inline void swap (t &a, t &b) {T tmp = A;a = B;B = tmp;} inline void read (int &x) {x = 0;char ch = getchar (), c = ch; while (Ch < ' 0 ' | | ch > ' 9 ') c = ch, ch = getchar (); while (Ch <= ' 9 ' && ch >= ' 0 ') x = x * + ch-' 0 ', ch = getchar (); if (c = = '-') × =-X;} const int INF = 0x3f3f3f3f;const int MAXN = + 10;const int dx[4] = {0,0,1,-1};const int dy[4] = {1,-1,0,0};int n, m, h AO[MAXN][MAXN], VIS1[MAXN * MAXN], VIS2[MAXN * MAXN], cnt1, Cnt2, LK1[MAXN * MAXN], LK2[MAXN * MAXN], VIS[MAXN * Maxn];cha R s[maxn][maxn];struct edge{intU,V,NXT; Edge (int _u, int _v, int _nxt) {u = _u;v = _v;nxt = _NXT;} Edge () {}}edge[100000];int HEAD[MAXN * MAXN], cnt;inline void Insert (int a, int b) {edge[++cnt] = Edge (A,b,head[a]); Head[a] = cnt;} int dfs (int x) {for (int pos = head[x];p os;pos = edge[pos].nxt) {int i = EDGE[POS].V; if (Vis[i]) continue; Vis[i] = 1; if (lk2[i] = = 1 | | DFS (LK2[I])) {Lk2[i] = x, lk1[x] = i; return 1; }} return 0;} void dfs1 (int x) {vis1[x] = 1; for (int pos = head[x];p os;pos = edge[pos].nxt) {int i = EDGE[POS].V; if (lk2[i] = =-1 | | vis1[lk2[i]]) continue; DFS1 (Lk2[i]); }}void dfs2 (int x) {vis2[x] = 1; for (int pos = head[x];p os;pos = edge[pos].nxt) {int i = EDGE[POS].V; if (lk1[i] = =-1 | | vis2[lk1[i]]) continue; DFS2 (Lk1[i]); }}int Main () {read (n), read (m); for (int i = 1;i <= n;++ i) scanf ("%s", S[i] + 1); for (int i = 1;i <= n;++ i) for (int j = 1;j <= m;++ j) if (s[i][j] = = ' # ') continue; else if ((i + J & 1)) Hao[i][j] = + + cnt1; else Hao[i][j] = + + Cnt2; Zochi right-pair for (int i = 1;i <= n;++ i) for (int j = 1;j <= m;++ j) if (s[i][j] = = '. ' && (i + j) & 1) {for (int k = 0;k < 4;++ k) {int x = i + dx[k ], y = j + dy[k]; if (x <= 0 | | x > N | | y <= 0 | | y > M | | s[x][y] = = ' # ') continue; Insert (Hao[i][j], hao[x][y]); }} memset (Lk1,-1, sizeof (LK1)); memset (LK2,-1, sizeof (LK2)); for (int i = 1;i <= cnt1;++ i) {memset (Vis, 0, sizeof (VIS)); DFS (i); } for (int i = 1;i <= cnt1;++ i) if (lk1[i] = =-1) dfs1 (i); CNT = 0;memset (head, 0, sizeof (head)); for (int i = 1;i <= n;++ i) for (int j = 1;j <= m;++ j) if (s[i][j] = = '. ' && (i + j) & 1) {for (int k = 0;k < 4;++ k) {int x = i + Dx[k], y = j + dy[k]; if (x <= 0 | | x > N | | y <= 0 | | y > M | | s[x][y] = = ' # ') continue; Insert (Hao[x][y], hao[i][j]); }} for (int i = 1;i <= cnt2;++ i) if (lk2[i] = =-1) dfs2 (i); int flag = 0; for (int i = 1;i <= n;++ i) for (int j = 1;j <= m;++ j) if (s[i][j] = = ' # ') continue; else if ((i + j) & 1 && vis1[hao[i][j]]) {if (!flag) printf ("win\n"), flag = 1; printf ("%d%d\n", I, j); } else if (! ( (i + j) & 1) && Vis2[hao[i][j]) {if (!flag) printf ("win\n"), flag = 1; printf ("%d%d\n", I, j); } if (!flag) printf ("Lose"); return 0;}
BZOJ1443: [JSOI2009] Game games