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. 关于BMP

    关于BMP位图的资料网上有很多,内容也比较基础.本文实现BMP位图的读取.显示.保存,并对一些重要的问题进行说明(包括字节对齐.内存中的存储顺序.调色板). BMP文件共包括文件头.信息头.调色板(位 ...

  2. (转)生产者/消费者问题的多种Java实现方式

    参考来源:http://blog.csdn.net/monkey_d_meng/article/details/6251879/ 生产者/消费者问题的多种Java实现方式 实质上,很多后台服务程序并发 ...

  3. mysql 三大范式【转载】

    第一范式(1NF,normal format):字段不能再分. 这是字段的原子性.例如:字段“学期时间”:2014-9-1,2015-1-15. 这个字段“学期时间”可以再分为“学期开始时间”,201 ...

  4. c#内存管理,垃圾回收和资源释放

    <1>关于虚拟内存的概念 Windows使用一个虚拟寻址系统,该系统把程序可用的内存地址映射到硬件内存中的实际地址上去,这些任务完全由windows后台管理,其实际结果是32位处理机上的每 ...

  5. ubuntu安装mysql多实例

    想要尝试mysql的读写分离,在云上安装完mysql之后突然想到一个问题:我本机是没有公网IP的. 开始尝试在唯一一台云服务器上安装多个mysql实例. 主要步骤: 1.新建MySQL目录 (1):新 ...

  6. canvas绘制基础

    初始接口 <body> <canvas id=“canvas”></canvas> <script> var canvas = document.get ...

  7. windows 查看某端口被占用情况

    百度经验 http://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html 基本命令 netstat -ano

  8. BZOJ 2157: 旅游 (2017.7.21 6:30-2017.7.21 15:38 今日第一题。。)

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1754  Solved: 765 Description Ray 乐忠于旅游,这次他来到了T 城.T ...

  9. Elasticsearch插件清单

    1.API插件:主要对Elasticsearch添加的API特性或者功能,通常用于搜索或者映射 2. 报警插件: 当Elasticsearch的索引指标超过阀值时就会触发 3. 分词插件:ik是比较好 ...

  10. CortexA7工业级迅为-iMX6UL开发板硬件和资料介绍

    商业级核心板 ARM Cortex-A7架构 主频高达528 MHz 核心板512M DDR内存 8G EMMC 存储 运行温度:-20℃ ~ +80℃ CPU集成电源管理 核心板尺寸仅:42mm*3 ...