bzoj:1443: [JSOI2009] Game games

Source: Internet
Author: User

Original title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1443

Anyway, I can't think of a series ...

First the checkerboard black and white dyeing, that is, the same diagonal color, so that a lattice up and down are different colors.

Then we will find that the whole lattice color of a person's walk is the same.

The black and white lattice as a point extracted, placed on both sides, it becomes a two-minute chart, the whole process of the game becomes like the augmentation of Hungarian algorithm.

This suggests that we may be related to binary graph matching.

If a point must be in the maximum match, and the first piece is placed here small yy as long as along the matching side walk small AA on GG.

Note that this is necessarily in the maximum match, so do not worry about the occurrence of a non-matching point after the small yy no way to go, at this time can be pseudo-augmented to maintain the maximum number of matches unchanged and the starting point is not in the matching point.

For Hungarian algorithms, it is possible to find all points that are not necessarily in the maximum match through similar pseudo-augmentation.

For network streams, the points that are not cut off adjacent sides of the Yuanhui are definitely the answer, and for other points that can be answered, you can reach the meeting point or from the source point by taking the opposite edge (a similar interleaved path to Hungary). That is, in the residual network, the source point can be reached and in the binary map near the point of the source point, can reach the meeting point and in the binary map near the side of the meeting point (no two restrictions on GG) are the answer point. (Note that a one-way edge is built, that is, the initial flow of the opposite edge is 0)

#include <cstdio>#include<algorithm>#defineMN 110001using namespacestd;intRead_p,read_ca;inlineintRead () {read_p=0; read_ca=GetChar ();  while(read_ca<'0'|| Read_ca>'9') read_ca=GetChar ();  while(read_ca>='0'&&read_ca<='9') read_p=read_p*Ten+read_ca- -, read_ca=GetChar (); returnread_p;}Const intfx[4]={1,-1,0,0},fy[4]={0,0,1,-1};structna{intY,f,ne;} B[MN];intn,m,l[mn],be[101][101],nm=0, s,t,num=1, d[mn],g[mn],c[mn],mmh=0;BOOLBO[MN],O_O[MN];Chars[101][101];inlinevoidAddintXintYintf) {b[++num].y=y;b[num].f=f;b[num].ne=l[x];l[x]=num;} Inlinevoid inch(intXintYintf) {Add (x,y,f); Add (Y,x,0);}intSapintXintf) {    if(x==t)returnF; intH=0, q;  for(intI=d[x];i;i=b[i].ne)if(b[i].f&&g[x]==g[b[i].y]+1) {Q=sap (B[i].y,min (fh,b[i].f)); B[I].F-=q;b[i^1].f+=q;h+=q;d[x]=L[x]; if(h==f)returnh; if(G[S]==NM)returnh; }    if(!--C[g[x]] g[s]=nm;++c[++g[x];d [x]=L[x]; returnh;}voidDfsintXBOOLB) {    if(Bo[x])return; BO[X]=1; o_o[x]^=C;  for(intI=l[x];i;i=b[i].ne)if(b[i].f==B) DFS (B[I].Y,B);}intMain () {registerinti,j,k; N=read (); m=read ();  for(i=1; i<=n;i++) scanf ("%s", s[i]+1);  for(i=1; i<=n;i++)     for(j=1; j<=m;j++)if(s[i][j]=='.') be[i][j]=++nm; S=++NM; t=++nm;  for(i=1; i<=n;i++)     for(j=1; j<=m;j++)    if(s[i][j]=='.')     for(k=0;k<4; k++)    if(s[i+fx[k]][j+fy[k]]=='.')    if((I+J) &1)inch(Be[i+fx[k]][j+fy[k]],be[i][j],1);Else inch(Be[i][j],be[i+fx[k]][j+fy[k]),1);  for(i=1; i<=n;i++)     for(j=1; j<=m;j++)    if(s[i][j]=='.')if(Mmh++,o_o[be[i][j]]= (I+J) &1))inch(Be[i][j],t,1);Else inch(S,be[i][j],1);  for(; g[s]<nm;mmh-=2*SAP (S,1E9)); if(!MMH)returnPuts"lose"),0; Puts ("WIN"); DFS (S,1);d FS (T,0);  for(i=1; i<=n;i++)     for(j=1; j<=m;j++)    if(s[i][j]=='.'&AMP;&AMP;BO[BE[I][J]]&AMP;&AMP;O_O[BE[I][J]]) printf ("%d%d\n", i,j);}
View Code

bzoj:1443: [JSOI2009] Game games

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.