ZOJ 2852 Beautiful Meadow(水题)

来源:互联网 发布:淘宝垃圾短信轰炸机 编辑:程序博客网 时间:2024/05/22 02:17

Beautiful Meadow

题目链接:

http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=2850

解题思路:

水题。

AC代码:

#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int dx[] = {-1,0,1,0},dy[] = {0,-1,0,1};int maze[15][15];bool check(int x,int y){    for(int i = 0; i < 4; ++i){        if(maze[x+dx[i]][y+dy[i]] == 0)            return true;    }    return false;}int main(){    int n,m;    while(scanf("%d%d",&n,&m),n+m){        memset(maze,-1,sizeof(maze));        int cnt = 0;        for(int i = 1; i <= n; ++i){            for(int j = 1; j <= m; ++j){                scanf("%d",&maze[i][j]);                if(maze[i][j])                    cnt++;            }        }        if(cnt == n*m){            puts("No");            continue;        }        int flag = 1;        for(int i = 1; i <= n && flag; ++i){            for(int j = 1; j <= m && flag; ++j){                if(maze[i][j] == 0 && check(i,j)){                    flag = 0;                }            }        }        if(flag)            puts("Yes");        else            puts("No");    }    return 0;}


0 0
原创粉丝点击