Beautiful Meadow


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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 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 <iostream>
using namespace std;
int main(){
int n, m;
int p[][];
int i, j, k;
while(cin >> n >> m){
if(n == && m == ){
break;
}
int flag = ;//表示没修剪过
for(i = ; i < n; i++){
for(j = ; j < m; j++){
cin >> p[i][j];
if(p[i][j] == )
flag = ;
}
}
if(flag == ){
cout << "No" << endl;
continue;
}
//判断第0行
for(k = ; k < m; k++){
if(p[][k] == && p[][k - ] == ){
cout << "No" << endl;
goto RL;
}
}
//判断第0列
for(k = ; k < n; k++){
if(p[k][] == && p[k - ][] == ){
cout << "No" << endl;
goto RL;
}
}
//判断第1——n-1行
for(i = ; i < n; i++){
for(j = ; j < m; j++){
if(p[i][j] == && p[i - ][j] == ){
cout << "No" << endl;
goto RL;
}
if(p[i][j] == && p[i][j - ] == ){
cout << "No" << endl;
goto RL;
}
}
}
cout << "Yes" << endl;
continue;
RL:
continue;
}
//system("pause");
return ;
}

总结:1.需要判断是不是、有没有,用一个标识符就行,此题可以不用一个变量做计数(判断1的个数是不是和矩阵大小一样,如果一样,则说明没有修剪,不漂亮)

2.现学的goto语句,第二层内循环想要直接结束第一层循环,用goto语句(以前不知道这么用。。)

zoj 2850 Beautiful Meadow的更多相关文章

  1. ZOJ 3213 Beautiful Meadow 简单路径 插头DP

    简单路径的题目,其实就是在状态后面多记了有多少个独立插头. 分类讨论独立插头: 1.只存在上插头或者左插头,可以选择作为独立插头. 2.都不存在上插头和左插头,选择作为独立插头的同时要标号为新的连通块 ...

  2. ZOJ 2850和ZOJ 1414

    下午上数据结构,结果竟然没有新题.T T果断上OJ来水一发 ZOJ 2850   Beautiful Meadow 传送门http://acm.zju.edu.cn/onlinejudge/showP ...

  3. zoj 2829 Beautiful Number

    Beautiful Number Time Limit: 2 Seconds      Memory Limit: 65536 KB Mike is very lucky, as he has two ...

  4. [ZOJ3213] Beautiful Meadow

    插头DP...网格图,有障碍,格子上有权值,求总权值最大的简单路径. 因为路径的起始点不确定..所以多开一维表示当前已经有多少个独立插头.. 只要不合并相同的联通块,并且已经用了2个独立插头,那就是一 ...

  5. ZOJ 2319 Beautiful People

    LIS.先按S降序升序再按B降序排序(如果B不按降序排序的话就会覆盖掉正解),然后再对B用O(nlog(n))的LIS求解就可以了.用d数组标记每个元素在上升序列中的位置,然后根据d倒着找id就可以了 ...

  6. 插头DP专题

    建议入门的人先看cd琦的<基于连通性状态压缩的动态规划问题>.事半功倍. 插头DP其实是比较久以前听说的一个东西,当初是水了几道水题,最近打算温习一下,顺便看下能否入门之类. 插头DP建议 ...

  7. 插头dp的几个模板

    /* ural1519 求经过全部可行点的哈密顿回路的个数 括号匹配法,转移有点复杂,可是时间空间比較小 */ #include<cstdio> #include<cstring&g ...

  8. poj 3100 (zoj 2818)||ZOJ 2829 ||ZOJ 1938 (poj 2249)

    水题三题: 1.给你B和N,求个整数A使得A^n最接近B 2. 输出第N个能被3或者5整除的数 3.给你整数n和k,让你求组合数c(n,k) 1.poj 3100 (zoj 2818) Root of ...

  9. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

随机推荐

  1. eclipse XML TAB键默认为四个空格

  2. HDU 5778 abs 数学

    http://acm.hdu.edu.cn/showproblem.php?pid=5778 这题的意思就是找离x最近的一个数y,且y是一个完全平方数,还是所有质因子都只能出现两次的完全平方数 一开始 ...

  3. MySQL优化步骤和my.cnf优化配置

    1.查看机器配置,指三大件:cpu.内存.硬盘 2.查看mysql配置参数 3.查看mysql运行状态,可以用mysqlreport工具来查看 4.查看mysql的慢查询 依次解决了以上问题之后,再来 ...

  4. 【译】建立属于你的个人高效系统——效率专家 Mike Vardy 教你如何设置一个简单的个人高效系统

    原文:http://mux.baidu.com/?p=5300 百度MUX 已经有太多的高效系统供人使用,而对于那些刚刚开始,想寻求更好方法完成他们任务,项目,目标的人来说,要做一个高效系统却是相当艰 ...

  5. javascript 找出数字数组中最大的数

    找出数字数组中最大的数 var Match = (function(){ var arr = null; var len = 0; return { max:function(arr,len){ ar ...

  6. 【转】数据库CRUD操作

    数据库CRUD操作 一.删除表   drop table 表名称 二.修改表 alter   table 表名称 add  列名 数据类型   (add表示添加一列) alter  table  表名 ...

  7. react基础语法(一)元素渲染和基础语法规则

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. RSA2

    进行签名的加密 package com.goboosoft.common.pay.util; import java.io.ByteArrayInputStream; import java.io.I ...

  9. linux 隐藏进程

    1.首先推荐一个后门程序https://github.com/f0rb1dd3n/Reptile 具体可以了解一下功能非常强大. 2.源码如下 root@ubuntu:/var/srt/libproc ...

  10. TUM好用的工具

    https://vision.in.tum.de/data/datasets/rgbd-dataset/tools?tdsourcetag=s_pctim_aiomsg