ZOJ 2850Beautiful Meadow

来源:互联网 发布:大闹天空坐骑进阶数据 编辑:程序博客网 时间:2024/05/16 03:35

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2850

#include<iostream>#include<cstdio>#include<string>#include<string.h>#include<cmath>#include<algorithm>using namespace std;int graph[20][20];int main(){    int n, m;    while (cin >> n >> m)    {        if (n == 0 && m == 0)break;        int cot0 = 0, cot1 = 0;        for (int i = 0; i < n; i++)        {            for (int j = 0; j < m; j++)            {                scanf("%d", &graph[i][j]);                if (graph[i][j] == 1)cot1++;                else cot0++;            }        }        if (cot0 == 0)        {            printf("No\n");            continue;        }        int flag = 1;        for (int i = 0; i < n; i++)        {            for (int j = 0; j < m; j++)            {                if (graph[i][j] == 0)                {                    if (i - 1 >= 0)                    {                        if (graph[i - 1][j] == 0)                        {                            flag = 0;                            goto there;                        }                    }                    if (i + 1 <n)                    {                        if (graph[i + 1][j] == 0)                        {                            flag = 0;                            goto there;                        }                    }                    if (j - 1 >= 0)                    {                        if (graph[i ][j-1] == 0)                        {                            flag = 0;                            goto there;                        }                    }                    if (j +1 < m)                    {                        if (graph[i ][j+1] == 0)                        {                            flag = 0;                            goto there;                        }                    }                }            }        }    there:        if (flag == 0)printf("No\n");        else printf("Yes\n");    }    return 0;}
0 0