URAL ——1249——————【想法题】
Time Limit:5000MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
| input | output |
|---|---|
2 2 |
No |
3 3 |
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——————【想法题】的更多相关文章
- HDU 4972 Bisharp and Charizard 想法题
Bisharp and Charizard Time Limit: 1 Sec Memory Limit: 256 MB Description Dragon is watching NBA. He ...
- CodeForces 111B - Petya and Divisors 统计..想法题
找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- ural 1249. Ancient Necropolis
1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bit ...
- HDU - 5969 最大的位或 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5969 (合肥)区域赛签到题...orz 题意:给你l,r,求x|y的max,x,y满足l<=x<=y ...
- HDU 4193 Non-negative Partial Sums(想法题,单调队列)
HDU 4193 题意:给n个数字组成的序列(n <= 10^6).求该序列的循环同构序列中,有多少个序列的随意前i项和均大于或等于0. 思路: 这题看到数据规模认为仅仅能用最多O(nlogn) ...
- CodeForces - 156B Suspects 逻辑 线性 想法 题
题意:有1~N,n(1e5)个嫌疑人,有m个人说真话,每个人的陈述都形如X是凶手,或X不是凶手.现在给出n,m及n个陈述(以+x/-X表示)要求输出每个人说的话是true ,false or notd ...
- URAL 1944 大水题模拟
D - Record of the Attack at the Orbit Time Limit:1000MS Memory Limit:65536KB 64bit IO Format ...
- 2016华中农业大学预赛 E 想法题
Problem E: Balance Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 205 Solved: 64[Submit][Status][We ...
随机推荐
- C#英文面试常见问题[转]
I was reading a post about some common C# interview questions, and thought I'd share some of mine. T ...
- loj #6046. 「雅礼集训 2017 Day8」爷
#6046. 「雅礼集训 2017 Day8」爷 题目描述 如果你对山口丁和 G&P 没有兴趣,可以无视题目背景,因为你估计看不懂 …… 在第 63 回战车道全国高中生大赛中,军神西住美穗带领 ...
- 51nod1228 序列求和(伯努利数)
题面 传送门 题解 \(O(n^2)\)预处理伯努利数 不知道伯努利数是什么的可以看看这篇文章 不过这个数据范围拉格朗日差值应该也没问题--吧--大概-- //minamoto #include< ...
- JVM高级特性与实践(一):Java内存区域 与 内存溢出异常
套用<围城>中的一句话,“墙外面的人想进去,墙里面的人想出来”,用此来形容Java与C++之间这堵内存动态分配和垃圾收集技术所围成的“围墙”就再合适不过了. 对于从事C.C++的开发人员而 ...
- 下载azure website的code
1.登陆kudu直接下载. http://www.concurrency.com/blog/use-azure-kudu-debug-azure-websites/ 2.FTP链接拷贝(可以忽略) 3 ...
- 搭建 docker + nginx + keepalived 实现Web应用的高可用(亲测)
1. 环境准备 下载 VMware : https://www.vmware.com/go/getplayer-win 下载 Centos : https://mirrors.a ...
- SDUT OJ 数据结构实验之链表一:顺序建立链表
数据结构实验之链表一:顺序建立链表 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- Linux 查看文件夹命令
1,按照时间升序 命令:ls -lrt 详细解释: -l use a long listing format 以长列表方式显示(详细信息方式) -t sort by modi ...
- mac 配置charles
从官网下载链接http://www.charlesproxy.com/download 附上注册码: Registered Name: https://zhile.io License Key: 48 ...
- tornado 10 长轮询和 websocket
tornado 10 长轮询和 websocket 一.长轮询 #在网页,我们经常扫码登录,那么问题来了,前端是如何知道用户在手机上扫码登录的呢 这里就需要用到长轮询 #长轮询 #客户端能够不断地向服 ...