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. 与Cookie相比,Web Storage存在的优势

    与Cookie相比,Web Storage存在不少的优势,概括为以下几点:1. 存储空间更大:能提供5MB的存储空间(不同浏览器的提供的空间不同),Cookie仅4KB2. 存储内容不会发送到服务器: ...

  2. VS配置本地IIS以域名访问

    1.IIS下配置自己的网站,添加主机名 2.修改hosts文件(C://Windows/System32/drivers/etc) 3.VS中配置项目Web服务器(选择外部主机)

  3. log4go折腾

    导包 go get -u github.com/alecthomas/log4go log4go.xml配置 <logging> <filter enabled="true ...

  4. AJPFX关于对集合中的元素删除操作和注意点

    import java.util.ArrayList;import java.util.Iterator;import java.util.List; public class ForeTest2 { ...

  5. linux小白成长之路13————用U盘安装linux服务器

    [内容指引] 制作CentOS安装引导盘: 安装CentOS: 相关设置: 一.制作CentOS安装引导盘 1.下载安装镜像文件 从官网下载iso文件: 网址:https://www.centos.o ...

  6. poj3616 Milking Time

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  7. CF782A Andryusha and Socks

    题意: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to ...

  8. Eclipse项目转Android Studio

    刚来某公司的时候,发现Android开发仍然还在使用Eclipse,编码无规范,渠道打包竟然手动,svn版本主干分支管理混乱,总之各种low... 对于有强迫症的我来说,属实不可忍.但无奈,新人一个, ...

  9. bat判断服务是否启动

    sc query|find "tomcat6" && echo yes || echo nosc query|find "eventlog" & ...

  10. c++正则表达式模板库GRETA的使用

    GRETA是微软研究院的一位前员工开发并开源的一个C++正则表达式库,兼容perl正则语法 官方介绍:“A fast, flexible, perl-compliant regular express ...