W-23 Tom's Meadow
来源:互联网 发布:淘宝梦想世界 编辑:程序博客网 时间:2024/06/12 01:00
Description
Tom's 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
解题思路:
题意为1.若有两个相近的数都为0,或2.所有数都为1,则输出No,此题中为了不让第一排第一列和最后一排最后一列成为特殊情况,构建数组a[13][13]并赋初值1,并a[1][1]成为首元素,这样第一排第一列和最后一排最后一列的周围也都有了值,可与其它数一同判断,
细节处理:
数组a的行数和列数要大于等于12
代码:
#include<iostream>using namespace std;int main(){int n,m;while(cin>>n>>m){if(n==0&&m==0) break;int i,j;int a[15][15];int flag=0,flag1=1;for(i=0;i<=14;i++)for(j=0;j<=14;j++)a[i][j]=1;for(i=1;i<=n;i++)for(j=1;j<=m;j++){cin>>a[i][j];if(a[i][j]==0) flag=1;}for(i=1;i<=n;i++)for(j=1;j<=m;j++){if((a[i][j]==0&&a[i-1][j]==0)||(a[i][j]==0&&a[i+1][j]==0)||(a[i][j]==0&&a[i][j-1]==0)||(a[i][j]==0&&a[i][j+1]==0))flag1=0;}if(flag&&flag1) cout<<"Yes"<<endl;else cout<<"No"<<endl;}return 0;}
- W-23 Tom's Meadow
- Jerry's Tom
- 正则表达式 ((/w*|(/w/s*/w*)*)(/w*/S))$ ((/w*|(/w/s*(.)*/w*)*)(/w*/S))$ .net 前后去掉(没有)空格
- 正则表达式 ((/w*|(/w/s*/w*)*)(/w*/S))$ ((/w*|(/w/s*(.)*/w*)*)(/w*/S))$ .net 前后去掉(没有)空格
- hdu1507Uncle Tom's Inherited Land*
- 1042 W's Cipher
- POJ1107 W's Cipher
- ZOJ1042-W`s Cipher
- ZJU1042-W‘s Cipher
- HDU 1507 Uncle Tom's Inherited Land*
- o4-tom's mystat.sql & mystat2.sql
- hdu 1507 Uncle Tom's Inherited Land*
- hdu Uncle Tom's Inherited Land*
- Hdu1507 Uncle Tom's Inherited Land*
- Hdu 1507 Uncle Tom's Inherited Land*
- HDOJ 1507 Uncle Tom's Inherited Land*
- ZOJ1516 Uncle Tom's Inherited Land
- HDU 1507 Uncle Tom's Inherited Land*
- C# 查找问题
- 网页调用QQ应用
- 浅谈HTML5前端开发学习路线
- 欢迎使用CSDN-markdown编辑器
- Matlab滑动条控件使用方法和注意事项
- W-23 Tom's Meadow
- Java基础----Eclipse的环境搭建
- Kubernetes计算资源管理--requests和limits(续2)
- C++基础知识复习--结构体类数组作为函数参数
- javamail QQ邮箱发送实例
- leetcode143. Reorder List
- 向ueditor中插入内容
- TCP三次握手、四次挥手
- Ubuntu14.04下安装NCL6.3.0过程