zoukankan      html  css  js  c++  java
  • [JSOI2009]游戏

    Description

    Input
    输入数据首先输入两个整数N,M,表示了迷宫的边长。 接下来N行,每行M个字符,描述了迷宫。

    Output
    若小AA能够赢得游戏,则输出一行"WIN",然后输出所有可以赢得游戏的起始位置,按行优先顺序输出 每行一个,否则输出一行"LOSE"(不包含引号)。

    Sample Input
    3 3
    .##
    ...

    .#

    Sample Output
    WIN
    2 3
    3 2

    HINT
    对于100%的数据,有1≤n,m≤100。 对于30%的数据,有1≤n,m≤5。


    首先对棋盘黑白染色,然后进行二分图匹配,若图中没有完备匹配,则先手必然将棋子放置在非关键点上,那么后手只能将棋子移动到关键点上,之后先手不断沿着匹配边移动棋子,因为最开始经过了一条非匹配边,所以后手不可能将棋子沿其他非匹配边移动

    然后由于二分图最大匹配的性质,先手总比后手多出一步,所以先手必胜

    反之,若存在完备匹配,则先手必败;因此我们只需要找到非关键点即可

    /*program from Wolfycz*/
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define inf 0x7f7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline char gc(){
    	static char buf[1000000],*p1=buf,*p2=buf;
    	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
    }
    inline int frd(){
    	int x=0,f=1; char ch=gc();
    	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline int read(){
    	int x=0,f=1; char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x<0)	putchar('-'),x=-x;
    	if (x>9)	print(x/10);
    	putchar(x%10+'0');
    }
    const int N=1e2;
    const int dx[4]={0,0,1,-1};
    const int dy[4]={-1,1,0,0};
    char map[N+10][N+10];
    int vis[N+10][N+10];
    bool can[N+10][N+10];
    int n,m,Time;
    bool in_map(int x,int y){return x>0&&x<=n&&y>0&&y<=m;}
    struct S1{
    	int x,y;
    	void insert(int _x,int _y){x=_x,y=_y;}
    }path[N+10][N+10];
    bool T(const S1 &a){return (!!a.x)||(!!a.y);}
    bool Extra(int x,int y){
    	for (int k=0;k<4;k++){
    		int tx=x+dx[k],ty=y+dy[k];
    		if (!in_map(tx,ty)||map[tx][ty]=='#')	continue;
    		if (vis[tx][ty]==Time)	continue;
    		vis[tx][ty]=Time;
    		if (!T(path[tx][ty])||Extra(path[tx][ty].x,path[tx][ty].y)){
    			path[tx][ty].insert(x,y);
    			path[x][y].insert(tx,ty);
    			return 1;
    		}
    	}
    	return 0;
    }
    void dfs(int x,int y){
    	if (can[x][y])	return;
    	can[x][y]=1;
    	for (int k=0;k<4;k++){
    		int tx=x+dx[k],ty=y+dy[k];
    		if (!in_map(tx,ty)||map[tx][ty]=='#')	continue;
    		dfs(path[tx][ty].x,path[tx][ty].y);
    	}
    }
    int main(){
    	n=read(),m=read();
    	for (int i=1;i<=n;i++)	scanf("%s",map[i]+1);
    	for (int i=1;i<=n;i++){
    		for (int j=1;j<=m;j++){
    			if ((i+j)&1){
    				++Time;
    				if (map[i][j]=='#')	continue;
    				Extra(i,j);
    			}
    		}
    	}
    	bool flag=0;
    	for (int i=1;i<=n;i++){
    		for (int j=1;j<=m;j++){
    			if (T(path[i][j]))	continue;
    			if (map[i][j]=='#')	continue;
    			dfs(i,j),flag=1;
    		}
    	}
    	if (!flag){
    		printf("LOSE
    ");
    		return 0;
    	}else{
    		printf("WIN
    ");
    		for (int i=1;i<=n;i++)
    			for (int j=1;j<=m;j++)
    				if (can[i][j])
    					printf("%d %d
    ",i,j);
    	}
    	return 0;
    }
    
  • 相关阅读:
    ORA-01935: missing user or role name
    ORA-00923: FROM keyword not found where expected
    ORA-00933: SQL command not properly ended
    ORA_12514:TNS:listener does not currently know of service requested in connect descriptor
    ORA-00918: column ambiguously defined
    ORA-01789: 查询块具有不正确的结果列数
    ORA-01789: query block has incorrect number of result columns
    ORA-01747
    ORA-01843: not a valid month
    ORA-00904: "I_LEVEL": invalid identifier
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/10249914.html
Copyright © 2011-2022 走看看