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语言编程学习开发的俄罗斯方块小游戏

    C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...

  2. winform列标题高度无法改变

    datagridview行为里把ColumnHeadersHeightSizeMode属性设置为EnableResizing 但好像会导致横向滚动条从底部跑到了中间,还不知道这个BUG的原因,将Col ...

  3. c语言数据结构学习心得——数据结构基本概念

    1.数据>数据元素>数据项      数据的基本单位是数据元素,数据元素的基本单位是数据项 2.运算的定义->针对逻辑结构 集合:同属于一个集合,无其他关系.(数学上的集合) 线性结 ...

  4. \\.\Global\vmx86: 系统找不到指定的文件

    使用vmware虚拟机时出现如下的错误: vmware安装无法打开内核设备 \\.\Global\vmx86: 系统找不到指定的文件 解决办法: 新建文件,将下面的代码拷贝进去: @Echo Off ...

  5. 24.Letter Combinations of a Phone Number(电话号对应的字符组合)

    Level:   Medium 题目描述: Given a string containing digits from 2-9 inclusive, return all possible lette ...

  6. 洛谷 P1149 火柴棒等式

    嗯....   这道题好讨厌啊!!!!   一开始莫名RE,然后发现数组小了,然后发现后面几个点总是WA,原来推的少了....   并且这道题的思路真的好水啊!!   先看一下题: 题目描述 给你n根 ...

  7. 转载---<html>与<body>

    关于根元素html以及body的对比,主要是遇到设置背景色的问题,这里转载张鑫旭的关于html和body对比的文.(直接贴过来,是为了以后自己方便看) 原文地址:http://www.zhangxin ...

  8. CentOS 中安装nginx

    Centos6.8 yum  安装 nginx  1:使用yum安装nginx,安装nginx库 [root@hadoop110 //]# rpm -Uvh http://nginx.org/pack ...

  9. redux超易学三篇之二(开始使用react-redux)

    其实 redux 真正让人感到混乱的还是在 react-redux 的使用中. 请配合完整代码参考~:完整源代码 也不是说混乱,主要是网上 推崇 最佳实践.学习一个新东西的时候,本来就很陌生,上来就用 ...

  10. 关于python中的round()和javascript中的round()的比较

    ps:python的round()和javascript的round()的比较: javascript:Math.round():正常的标准舍入,就像我们学的数学课本上面的规则 python:pyth ...