您的位置:首页 > 其它

ZOJ 2850 Beautiful Meadow

2016-02-19 20:17 375 查看
题目链接: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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: