ural 1249. Ancient Necropolis
2015-12-26 10:28
323 查看
1249. Ancient Necropolis
Time limit: 5.0 secondMemory limit: 4 MB
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.Samples
input | output |
---|---|
2 2 0 1 1 1 | No |
3 3 0 0 1 1 1 0 1 1 0 | Yes |
Problem Source: Open collegiate programming contest for student teams, Ural State University, March 15, 2003
Tags: none (hide tags for unsolved problems)
Difficulty: 210
题意:n*m的矩阵中,所有1组成的连通块是不是矩形。
分析:暴力。
但注意存下整张图不可能,所以只能用相邻两行比较。
/** Create By yzx - stupidboy */ #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <deque> #include <vector> #include <queue> #include <iostream> #include <algorithm> #include <map> #include <set> #include <ctime> #include <iomanip> using namespace std; typedef long long LL; typedef double DB; #define MIT (2147483647) #define INF (1000000001) #define MLL (1000000000000000001LL) #define sz(x) ((int) (x).size()) #define clr(x, y) memset(x, y, sizeof(x)) #define puf push_front #define pub push_back #define pof pop_front #define pob pop_back #define ft first #define sd second #define mk make_pair inline int Getint() { int ret = 0; char ch = ' '; bool flag = 0; while(!(ch >= '0' && ch <= '9')) { if(ch == '-') flag ^= 1; ch = getchar(); } while(ch >= '0' && ch <= '9') { ret = ret * 10 + ch - '0'; ch = getchar(); } return flag ? -ret : ret; } const int N = 3010; int n, m, graph , data ; inline void Input() { // scanf("%d%d", &n, &m); n = Getint(); m = Getint(); } inline void Move(int &l, int &r, int *arr) { for(l = r + 1; l <= m && !arr[l]; l++); for(r = l; r < m && arr[r + 1]; r++); } inline void Solve() { bool ans = 1; for(int i = 1; i <= n && ans; i++) { for(int j = 1; j <= m; j++) data[j] = Getint(); int l1, r1 = 0, l2, r2 = 0; for(l1 = 1; l1 <= m && !graph[l1]; l1++); for(r1 = l1; r1 < m && graph[r1 + 1]; r1++); for(l2 = 1; l2 <= m && !data[l2]; l2++); for(r2 = l2; r2 < m && data[r2 + 1]; r2++); while(l1 <= m && l2 <= m) { if(r1 < l2) Move(l1, r1, graph); else if(r2 < l1) Move(l2, r2, data); else if(l1 == l2 && r1 == r2) { Move(l1, r1, graph); Move(l2, r2, data); } else { ans = 0; break; } } for(int j = 1; j <= m; j++) graph[j] = data[j]; } puts(ans ? "Yes" : "No"); } int main() { freopen("a.in", "r", stdin); Input(); Solve(); return 0; }
View Code
相关文章推荐
- Linux系统档案与文件系统的压缩与打包
- openstack live-migration
- ubuntu系统上phabricator安装与配置
- Linux/CentOS关闭图形界面(X-window)和启用图形界面命令
- CentOS安装glibc-2.14
- tomcat所部署的项目设置
- opencart及其中国版mycncart系统安装后,商品图片所需注意事项
- mycncart及opencart后台忘记密码
- ural 1145. Rope in the Labyrinth
- ural 1145. Rope in the Labyrinth
- 学习笔记(9)——shellscript
- centos下怎么设置Apache 开机启动!
- 2014系统架构师大会随感
- Linux源码查看
- Docker 从零开始制作基础镜像[centos]
- Copy-on-write
- Maven自动部署war包到Tomcat
- ARMv8 Linux内核异常处理过程分析
- Linux文件夹对比并提取的差分文件技巧-rsync的妙用
- 第一次作业之马哥Linux培训2015第二期