bzoj1443 [JSOI2009] Game games

Source: Internet
Author: User

Apparently by '. ' constitute a two-dimensional map, not to go to repeat the initiator must be defeated points.

Situation 1 for a binary graph maximum match in the non-essential point, the initiator can only move to one not traversed by the matching edge (it is not possible to never match the point along the matching edge to other unmatched points), the hand can be moved to the other side of the matching side, due to the limited end of the match edge can not operate so the initiator will fail

Situation 2 for a two-figure maximum match in the necessary points, the initiator can be moved along the matching edge each time, the hand can only walk to a not pass the matching edge (from the necessary points along the matching edge walk does not go to the unmatched point), because the matching edge of the final hand can not operate so the initiator win.

Therefore, the answer is to find the non-essential point in the maximum match of two graph. You can first find a maximum match, and then never match the point of departure from the staggered track to look for other non-essential points.

#include <cstdio>intn,m;Chars[ -][ -];intxs[]={-1,0,1,0};intys[]={0,-1,0,1};intpx[ -][ -],py[ -][ -],d[ -][ -],now,v[ -][ -],ed[ -][ -];BOOLDfsintXinty) {D[x][y]=Now ; if(Px[x][y]&&d[px[x][y]][py[x][y]]!=now)returnDFS (Px[x][y],py[x][y]);  for(intI=0;i<4; i++){        intx1=x+xs[i],y1=y+Ys[i]; if(d[x1][y1]!=now&&s[x1][y1]=='.'&&!Px[x1][y1]) {Px[x][y]=x1;py[x][y]=Y1; PX[X1][Y1]=x;py[x1][y1]=y; return 1; }    }     for(intI=0;i<4; i++){        intx1=x+xs[i],y1=y+Ys[i]; if(d[x1][y1]!=now&&s[x1][y1]=='.'&&DFS (X1,Y1)) {Px[x][y]=x1;py[x][y]=Y1; PX[X1][Y1]=x;py[x1][y1]=y; return 1; }    }    return 0;}voidDFS2 (intXinty) {    if(ed[x][y]| | s[x][y]!='.')return; Ed[x][y]=1; V[x][y]=1;  for(intI=0;i<4; i++){        intx1=x+xs[i],y1=y+Ys[i]; if(Px[x1][y1]) DFS2 (px[x1][y1],py[x1][y1]); }}intMain () {intA=0; scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) scanf ("%s", s[i]+1);  for(intI=1; i<=n;i++){         for(intj=1; j<=m;j++){            if(s[i][j]=='.'&&!Px[i][j]) {                ++Now ; A+=DFS (I,J); }        }    }     for(intI=1; i<=n;i++){         for(intj=1; j<=m;j++){            if(s[i][j]=='.'&AMP;&AMP;!PX[I][J]) v[i][j]=1; }    }     for(intI=1; i<=n;i++){         for(intj=1; j<=m;j++){            if(s[i][j]=='.'&&!Px[i][j]) DFS2 (I,J); }    }    BOOLwin=0;  for(intI=1; i<=n;i++){         for(intj=1; j<=m;j++){            if(V[i][j]) win=1; }} puts (Win?"WIN":"lose");  for(intI=1; i<=n;i++){         for(intj=1; j<=m;j++){            if(V[i][j]) printf ("%d%d\n", i,j); }    }    return 0;}

bzoj1443 [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.