Bzoj 1443 jsoi 2009 Games Game binary diagram + game

Source: Internet
Author: User

The main idea: to give a bad point of the grid diagram, each time moving pieces to the adjacent lattice, the request lattice can not be repeated, ask if there is a winning strategy, if there is, output all the pieces can be placed on the initial position.


Idea: A very classic two-figure game model, will be black and white dyeing, it becomes a two-minute map. After the maximum match, if it is on the side of the match, each time the initiator from the left to the right, the hand will be able to come back from the right, so that is the initiator lost. See details: http://blog.sina.com.cn/s/blog_76f6777d0101inwe.html

Set up the network flow model, run the maximum flow, on the residual network from S can be found on the left side of the point and the right to find the point of T is to meet the requirements of the point.


CODE:

#define _crt_secure_no_warnings#include <queue> #include <cstdio> #include <cstring> #include < iostream> #include <algorithm> #define MAX 2100#define maxp 20100#define maxe 1000010#define S 0#define T (MAXP-1 ) #define INF 0x3f3f3f3fusing namespace Std;const int dx[] = {0,1,-1,0,0};const int dy[] = {0,0,0,1,-1};int Ans[maxp];bool V[maxp];struct maxflow{int head[maxp],total;int next[maxe],aim[maxe],flow[maxe];int Deep[MAXP]; Maxflow (): Total (1) {}void Add (int. x,int Y,int f) {next[++total] = head[x];aim[total] = Y;flow[total] = f;head[x] = total;} void Insert (int x,int y,int f) {//cout << x << ' << y << ' << f << endl; ADD (X,Y,F); ADD (y,x,0);} BOOL BFS () {static queue<int> Q;while (!q.empty ()) Q.pop () memset (deep,0,sizeof (deep));d eep[s] = 1;q.push (S); while (!q.empty ()) {int x = Q.front (), Q.pop (), for (int i = head[x]; i; i = Next[i]) if (Flow[i] &&!deep[aim[i]) {de Ep[aim[i]] = deep[x] + 1;q.push (aim[i]); if (aim[i] = = T) rEturn true;}} return false;} int dinic (int x,int f) {if (x = = T) return F;int temp = f;for (int i = head[x]; i; i = Next[i]) if (Flow[i] && Deep[aim [i]] = = Deep[x] + 1 && temp) {int away = Dinic (Aim[i],min (flow[i],temp)); if (!away) deep[aim[i]] = 0;flow[i]-= away ; flow[i^1] + = away;temp-= away;} return f-temp;}} Solver;int M,n;char s[max][max];int num[max][max];bool col[maxp];bool t[maxp];void DFS (int x,int f) {t[x] = true;if (col[x ] = = F && x! = S && x! = T) ans[++ans[0]] = x;for (int i = solver.head[x]; i; i = Solver.next[i]) if (solver.f Low[i] = = f &&!t[solver.aim[i]]) DFS (solver.aim[i],f);} void Getans () {DFS (s,1); memset (t,false,sizeof (t));D FS (t,0);} inline void OutPut (int x) {printf ("%d%d\n", (x-1)/n + 1, (x-1)% n + 1);}  int main () {cin >> m >> n;for (int i = 1; I <= m; ++i) scanf ("%s", S[i] + 1); int cnt = 0;for (int i = 1; I <= M ++i) for (int j = 1; J <= N, ++j) num[i][j] = ++cnt;for (int i = 1; I <= m; ++i) for (int j = 1; j <= N; ++j{if (s[i][j] = = ' # ') continue;if (! ( (i + j) &1)) Solver. Insert (s,num[i][j],1), col[num[i][j]] = true;else {solver. Insert (num[i][j],t,1); continue;} for (int k = 1; k <= 4; ++k) {int FX = i + dx[k],fy = j + dy[k];if (!fx | |!fy | | FX > M | | fy > N) continue;if (s[fx ][fy] = = '. ') Solver. Insert (num[i][j],num[fx][fy],1);}} while (solver. BFS ()) Solver. Dinic (S,inf); Getans (), if (!ans[0]) puts ("Lose"), else {puts ("WIN"); sort (ans + 1,ans + ans[0] + 1); for (int i = 1; I <= ans[0]; ++i) OUTPU T (Ans[i]);} return 0;}


Bzoj 1443 jsoi 2009 Games Game binary diagram + game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.