zoj-【2850 】
来源:互联网 发布:剑灵陈苏儿捏脸数据 编辑:程序博客网 时间:2024/05/18 03:36
Beautiful Meadow
Tom has a meadow in his garden. He divides it into N * M squares. Initially all the squares were covered with grass. He mowed down the grass on some of the squares and thinks the meadow is beautiful if and only if
- Not all squares are covered with grass.
- No two mowed squares are adjacent.
Two squares are adjacent if they share an edge. Here comes the problem: Is Tom's meadow beautiful now?
Input
The input contains multiple test cases!
Each test case starts with a line containing two integers N, M (1 <= N, M <= 10) separated by a space. There follows the description of Tom's Meadow. There're N lines each consisting of M integers separated by a space. 0(zero) means the corresponding position of the meadow is mowed and 1(one) means the square is covered by grass.
A line with N = 0 and M = 0 signals the end of the input, which should not be processed
Output
One line for each test case.
Output "Yes" (without quotations) if the meadow is beautiful, otherwise "No"(without quotations).
Sample Input
2 2
1 0
0 1
2 2
1 1
0 0
2 3
1 1 1
1 1 1
0 0
Sample Output
Yes
No
No
#include<cstdio>int map[20][20];int dx[4]={-1,1,0,0};int dy[4]={0,0,1,-1}; int main(){int n,m;while(~scanf("%d%d",&n,&m)&&n,m){int i,j;for(i=0;i<n;++i)for(j=0;j<m;++j)scanf("%d",&map[i][j]);int tag=1,sum=0;for(i=0;i<n&&tag;++i){for(j=0;j<m&&tag;++j){if(!map[i][j]){for(int k=0;k<4;++k){int tx=i+dx[k];int ty=j+dy[k];if(tx>=0&&tx<n&&ty>=0&&ty<m&&!map[tx][ty])tag=0; }}else++sum; } }if(!tag||n*m==sum)printf("No\n");elseprintf("Yes\n"); } return 0;}
- zoj 2850
- ZOJ-2850
- zoj-【2850 】
- ZOJ 2850和ZOJ 1414
- zoj 2850 Beautiful Meadow
- ZOJ 2850 Beautiful Meadow
- ZOJ 2850 Beautiful Meadow
- ZOJ 2850 Beautiful Meadow
- zoj 2850 Beautiful Meadow
- ZOJ 2850 Beautiful Meadow
- ZOJ 2850Beautiful Meadow
- ZOJ 2850 Beautiful Meadow
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- 程序猿眼里的高并发(上)
- java多线程
- Iometer存储测试工具参数说明- 2 Access Specifications
- Linux设备模型(1)_基本概念
- ANDROID 设置状态栏与标题背景颜色一致
- zoj-【2850 】
- 系统移植学习笔记
- ssh
- 用[记事本]查杀EXE病毒
- CocoaPods pod install很慢以及The `master` repo requires CocoaPods 1.0.0报错
- oracle 初体验-pl/sql developer 连接设置
- IP协议
- CentOS下安装JDK的三种方法
- Git和GitHub学习笔记