Ancient Necropolis

Time Limit:5000MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u

Description

Aerophotography data provide a bitmap picture of a hard-to-reach region. According to the suggestions of scientists, this region is a cemetery of an extinct civilization. Indeed, the picture, having been converted to a binary form, shows distinctly visible areas, dark (marked with symbols 1) and light (marked with 0). It seems that the dark areas are tombstones. It's easy to either confirm or reject the hypothesis since the race that lived in the region knew astronomy, so tombstones were always oriented along the Earth's parallels and meridians. That is why the dark areas in the picture should have the form of rectangles with the sides parallel to the axes. If it is so, then we indeed have a picture of a cemetery of an extinct race. Otherwise, new hypotheses should be suggested.

Input

The first input line contains two integers N and M, which are the dimensions of the picture provided by the aerophotography. Each of the next N lines contains M zeros or ones separated with a space. The numbers N and М do not exceed 3000.

Output

Output "Yes" if all connected dark areas in the picture are rectangles and "No" otherwise.

Sample Input

input output
2 2
0 1
1 1
No
3 3
0 0 1
1 1 0
1 1 0
Yes

题目大意:问你在给出的n*m的矩阵中,所有1组成的连通块儿是不是矩形。如果是,输出“Yes”否则输出“No”。

解题思路:在开始的时候,没看内存,只看了时限,感觉可以先找到矩形的长,然后暴力宽,把矩形标记出来,如果发现有不合格的,就直接退出。但是交上去发现超内存。。。最后通过用bitset优化,终于过了内存,但是却又超时了。。。感觉方法有问题,赛后看了别人的代码,发现原来别人的思路更简单,就是每次枚举一个2*2的正方形,判断是不是形成了三角形,发现如果不是矩形的话,必然要形成一个三角形,然后就判断是不是有三个1。如果是三角形的话,说明不满足条件,标记一下结果。   其实我们只要存储两行的结果就行了,奇行、偶行,然后交替存储。

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<bitset>
#include<iostream>
using namespace std;
const int maxn = 3100;
int r1[maxn], r2[maxn];
bool jud(int a,int b,int c,int d){
int ret = 0;
if(a==1) ret++;
if(b==1) ret++;
if(c==1) ret++;
if(d==1) ret++;
if(ret == 3)
return true;
return false;
}
int main(){
int n,m;
while(cin>>n>>m){
int flag = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(i%2){
scanf("%d",&r1[j]);
}else{
scanf("%d",&r2[j]);
}
if(i != 1 && j != 1 && !flag)
flag = jud(r1[j],r1[j-1],r2[j],r2[j-1]);
}
}
if(flag) puts("No\n");
else puts("Yes");
}
return 0;
} /*
3 5
0 0 0 0 0
0 1 1 1 0
1 0 1 0 1 3 5
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0 3 3
0 0 1
1 1 0
0 0 1
*/

  

URAL ——1249——————【想法题】的更多相关文章

  1. HDU 4972 Bisharp and Charizard 想法题

    Bisharp and Charizard Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching NBA. He ...

  2. CodeForces 111B - Petya and Divisors 统计..想法题

    找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...

  3. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

  4. ural 1249. Ancient Necropolis

    1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bit ...

  5. HDU - 5969 最大的位或 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5969 (合肥)区域赛签到题...orz 题意:给你l,r,求x|y的max,x,y满足l<=x<=y ...

  6. HDU 4193 Non-negative Partial Sums(想法题,单调队列)

    HDU 4193 题意:给n个数字组成的序列(n <= 10^6).求该序列的循环同构序列中,有多少个序列的随意前i项和均大于或等于0. 思路: 这题看到数据规模认为仅仅能用最多O(nlogn) ...

  7. CodeForces - 156B Suspects 逻辑 线性 想法 题

    题意:有1~N,n(1e5)个嫌疑人,有m个人说真话,每个人的陈述都形如X是凶手,或X不是凶手.现在给出n,m及n个陈述(以+x/-X表示)要求输出每个人说的话是true ,false or notd ...

  8. URAL 1944 大水题模拟

    D - Record of the Attack at the Orbit Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format ...

  9. 2016华中农业大学预赛 E 想法题

    Problem E: Balance Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 205  Solved: 64[Submit][Status][We ...

随机推荐

  1. C#多线程编程实战1.2暂停线程(休眠)

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  2. 20165219第4次实验《Android程序设计》实验报告

    20165219第4次实验<Android程序设计>实验报告 一.实验内容及步骤 (一)Android Stuidio的安装Hello world测试 要求 参考http://www.cn ...

  3. #论文笔记# [pix2pixHD] High-Resolution Image Synthesis and Semantic Manipulation with Conditional GANs

    Ting-Chun Wang, Ming-Yu Liu, Jun-Yan Zhu, Andrew Tao, Jan Kautz, and Bryan Catanzaro. "High-Res ...

  4. 【bzoj1066】: [SCOI2007]蜥蜴 图论-最大流

    [bzoj1066]: [SCOI2007]蜥蜴 把石柱拆点,流量为高度 然后S与蜥蜴连流量1的边 互相能跳到的石柱连inf的边 石柱能到边界外的和T连inf的边 然后跑dinic就好了 /* htt ...

  5. Java面向对象之构造代码块 入门实例

    一.基础概念 1.构造代码块,给所有对象进行初始化. 2.构造函数,只给对应的对象初始化. 3.局部代码块,控制局部变量的生命周期. 二.实例代码 class Person { private int ...

  6. 百度编辑器 Ueditor使用记录

    Ueditor官网: http://fex.baidu.com/ueditor/#dev-bale_width_grunt UeditorAPI文档: https://ueditor.baidu.co ...

  7. table中thead固定一直在最上面

    <link rel="shortcut icon" href="favicon.ico"> <link href="css/boot ...

  8. 简单了解树形DP

    今天在B站看了一个树形DP教学视频有所收获,做一个小小的总结 AV号和链接在这:av12194537 那么先介绍一下树形DP 树形DP就是在树这个特殊的数据结构上进行的DP.有两种方向:自顶向下和自底 ...

  9. webpack 4.0 安装出现的小问题 (One CLI for webpack must be installed)

    安装的webpack版本是4.11.0,运行命令npm start 提示:One CLI for webpack must be installed. These are recommended ch ...

  10. java代码将excel文件中的内容列表转换成JS文件输出

    思路分析 我们想要把excel文件中的内容转为其他形式的文件输出,肯定需要分两步走: 1.把excel文件中的内容读出来: 2.将内容写到新的文件中. 举例 一张excel表中有一个表格: 我们需要将 ...