博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZCMU新人训练赛-B
阅读量:6224 次
发布时间:2019-06-21

本文共 1750 字,大约阅读时间需要 5 分钟。

 
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

  1. Not all squares are covered with grass.
  2. 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 NM (1 <= NM <= 10) separated by a space. There follows the description of Tom's Meadow. There're Nlines 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

<b< dd="">

Output

 

One line for each test case.

Output "Yes" (without quotations) if the meadow is beautiful, otherwise "No"(without quotations).

<b< dd="">

Sample Input

 

2 2

1 0
0 1
2 2
1 1
0 0
2 3
1 1 1
1 1 1
0 0

<b< dd="">

Sample Output

 

Yes

No
No

 

 

1 #include 
2 using namespace std; 3 bool arr[10][10]; 4 int main() 5 { 6 int n,m; 7 while(cin>>n>>m&&n!=0) 8 { 9 bool flag=true;10 int sum=0;11 for(int i=0;i
>arr[i][j];17 sum+=arr[i][j];18 if((arr[i][j]==0&&j>0&&arr[i][j-1]==0)||(i>0&&arr[i-1][j]==0&&arr[i][j]==0))19 {20 flag=false;21 22 }23 }24 }25 26 if(flag&&sum!=m*n)27 cout<<"Yes"<
View Code

 

转载于:https://www.cnblogs.com/Roni-i/p/7286065.html

你可能感兴趣的文章
六个人如何运维一万台服务器?
查看>>
nandflash学习1——导致nandflash反转的原因【转】
查看>>
Windows Phone 7发布啦
查看>>
租房新体验:AI机器人中介带你看房
查看>>
git版本控制&&github的使用
查看>>
权限设计之一
查看>>
如何使用网络库实现应用级消息收发
查看>>
Linux中断(interrupt)子系统之二:arch相关的硬件封装层【转】
查看>>
Django - 模板
查看>>
Java刷题知识点之什么是死锁、死锁产生的4个必要条件、死锁的解除与预防
查看>>
ArcGIS Engine对象库
查看>>
图片在保存的时候===》出现这个异常:GDI+ 中发生一般性错误
查看>>
Hadoop MapReduce编程 API入门系列之wordcount版本2(六)
查看>>
分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控
查看>>
运行灵活网页布局的示例程序
查看>>
Android -- Service绑定解绑和aidl
查看>>
它们的定义AlertDialog(二)
查看>>
SQL Server-聚焦计算列或计算列持久化查询性能(二十二)
查看>>
ten sentences(31-40)
查看>>
设计模式(二)工厂方法(创建型)
查看>>