Solution of ZOJ 2850 Beautiful Meadow

来源:互联网 发布:皮肤不好 知乎 编辑:程序博客网 时间:2024/05/16 06:09


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 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


Source: Zhejiang Provincial Programming Contest 2007

 

 


 

分析:本题关键点在于统计0的个数以及搜索是否存在纵向和横向两个方向之一存在连续0的情况。

下面给出我的实现代码:

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 老人坐飞机找不到登机口怎么办 儿童不能值机怎么办 飞机上旅客刁难怎么办 飞机上婴儿哭闹怎么办 飞机上婴儿啼哭怎么办 飞机儿童陪护手续怎么办 孕妇感冒鼻子堵怎么办 孕妇用了眼药水怎么办 孕妇用眼药水了怎么办 错过了登机时间怎么办 过了登机时间怎么办 孩子不喜欢做作业怎么办 宝宝腿不一样粗怎么办 一个小腿肿了怎么办 左右小腿不一样粗怎么办 小孩不敢自己睡怎么办 小孩不一个人睡怎么办 晚上一个人睡觉害怕怎么办 孩子自己睡害怕怎么办 小孩晚上睡觉怕怎么办 小孩分房睡害怕怎么办 坐飞机不认识字怎么办 科目一不识字怎么办 孩子不自己睡觉怎么办 70岁老人坐高铁怎么办 八岁儿童怎么办护照 第一次坐飞机有点紧张怎么办 坐飞机恐高耳鸣怎么办 火车坐过站怎么办 凌晨的火车应该怎么办 高铁坐过一站怎么办 宝宝断奶瘦了怎么办 第一次坐飞机怕晕机怎么办 焦虑症怕坐飞机怎么办 新生宝宝老是哭闹怎么办 宝宝坐飞机后哭闹怎么办 飞机经济舱不支持退票怎么办 证件被单位扣押怎么办 小孩高烧41度怎么办 国际航班未成年托管怎么办手续 如果飞机上发烧怎么办