zoj 2850 Beautiful Meadow
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
- Not all squares are covered with grass.
- 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
#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的更多相关文章
- ZOJ 3213 Beautiful Meadow 简单路径 插头DP
简单路径的题目,其实就是在状态后面多记了有多少个独立插头. 分类讨论独立插头: 1.只存在上插头或者左插头,可以选择作为独立插头. 2.都不存在上插头和左插头,选择作为独立插头的同时要标号为新的连通块 ...
- ZOJ 2850和ZOJ 1414
下午上数据结构,结果竟然没有新题.T T果断上OJ来水一发 ZOJ 2850 Beautiful Meadow 传送门http://acm.zju.edu.cn/onlinejudge/showP ...
- zoj 2829 Beautiful Number
Beautiful Number Time Limit: 2 Seconds Memory Limit: 65536 KB Mike is very lucky, as he has two ...
- [ZOJ3213] Beautiful Meadow
插头DP...网格图,有障碍,格子上有权值,求总权值最大的简单路径. 因为路径的起始点不确定..所以多开一维表示当前已经有多少个独立插头.. 只要不合并相同的联通块,并且已经用了2个独立插头,那就是一 ...
- ZOJ 2319 Beautiful People
LIS.先按S降序升序再按B降序排序(如果B不按降序排序的话就会覆盖掉正解),然后再对B用O(nlog(n))的LIS求解就可以了.用d数组标记每个元素在上升序列中的位置,然后根据d倒着找id就可以了 ...
- 插头DP专题
建议入门的人先看cd琦的<基于连通性状态压缩的动态规划问题>.事半功倍. 插头DP其实是比较久以前听说的一个东西,当初是水了几道水题,最近打算温习一下,顺便看下能否入门之类. 插头DP建议 ...
- 插头dp的几个模板
/* ural1519 求经过全部可行点的哈密顿回路的个数 括号匹配法,转移有点复杂,可是时间空间比較小 */ #include<cstdio> #include<cstring&g ...
- 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 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
随机推荐
- 【转载】(0, eval)(‘this’)
var window = this || (0, eval)('this') 在avalon源码中有这么一行代码,var window = this很容易理解 这里复习一下Global Object: ...
- 机器学习概念之特征处理(Feature processing)
不多说,直接上干货! 肯定也有不少博友,跟我一样,刚开始接触的时候,会对这三个概念混淆. 以下是,特征处理.特征提取.特征转换和特征选择的区别! 特征处理主要包含三个方面:特征提取.特征转换和特征选择 ...
- .net core跨域设置
services.AddCors(options => options.AddPolicy("AllowSameDomain", builder => builder. ...
- leetcode315 Count of Smaller Numbers After Self
思路: bit + 离散化. 实现: #include <bits/stdc++.h> using namespace std; class Solution { public: int ...
- 【学习笔记】深入理解js原型和闭包(0)——目录
文章转载:https://www.cnblogs.com/wangfupeng1988/p/4001284.html 说明: 本篇文章一共16篇章,外加两篇后补的和一篇自己后来添加的学习笔记,一共19 ...
- PHP环境搭建Zend Studio 10.6.2+WampServer2.4
址:http://www.zend.com/en/products/studio/downloads直接下载地址:http://downloads.zend.com/studio-eclipse/10 ...
- Linux/Windows 实用工具简记
以下只是开发中可能用的比较多的工具,另外还有其他很多未曾提及的实用工具.Linux篇: 1.链接过程的调试:主要用于查看构建过程:如链接时加载的动态库以及运行时加载动态库过程的调试 支持LD_DEBU ...
- swift Equatable 函数签名的测试
struct Degoo:Equatable { var lex:String var pex:String static func == (left:Degoo, right:Degoo) -> ...
- Codeforces Round #539 (Div. 2) C. Sasha and a Bit of Relax(前缀异或和)
转载自:https://blog.csdn.net/Charles_Zaqdt/article/details/87522917 题目链接:https://codeforces.com/contest ...
- 1-2 编程基础 GDB程序调试
简介 GDB是GNU发布的一款功能强大的程序调试工具.GDB主要完成下面三个方面的功能: 1.启动被调试程序 2.让被调试的程序在指定的位置停住. 3.当程序被停住时,可以检查程序状态(如变量值). ...