Recover Polygon (easy)
The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.
Heidi knows that the lair can be represented as a rectangle on a lattice, with sides parallel to the axes. Each vertex of the polygon occupies an integer point on the lattice. For each cell of the lattice, Heidi can check the level of Zombie Contamination. This level is an integer between 0 and 4, equal to the number of corners of the cell that are inside or on the border of the rectangle.
As a test, Heidi wants to check that her Zombie Contamination level checker works. Given the output of the checker, Heidi wants to know whether it could have been produced by a single non-zero area rectangular-shaped lair (with axis-parallel sides).
The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 50). The next N lines each contain Ncharacters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0and 4.
Cells are given in the same order as they are shown in the picture above: rows go in the decreasing value of y coordinate, and in one row cells go in the order of increasing x coordinate. This means that the first row corresponds to cells with coordinates(1, N), ..., (N, N) and the last row corresponds to cells with coordinates (1, 1), ..., (N, 1).
The first line of the output should contain Yes if there exists a single non-zero area rectangular lair with corners on the grid for which checking the levels of Zombie Contamination gives the results given in the input, and No otherwise.
6
000000
000000
012100
024200
012100
000000
Yes
The lair, if it exists, has to be rectangular (that is, have corners at some grid points with coordinates (x1, y1), (x1, y2), (x2, y1), (x2, y2)), has a non-zero area and be contained inside of the grid (that is, 0 ≤ x1 < x2 ≤ N, 0 ≤ y1 < y2 ≤ N), and result in the levels of Zombie Contamination as reported in the input.
分析:四个角是1,边上是2,内部是4,检查一下即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e2+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,x[],y[];
char a[maxn][maxn];
bool check()
{
int i,j;
rep(i,,)rep(j,,)if(a[x[i]][y[i]]!='')return false;
rep(i,x[]+,x[]-)if(a[i][y[]]!='')return false;
rep(i,x[]+,x[]-)if(a[i][y[]]!='')return false;
rep(i,y[]+,y[]-)if(a[x[]][i]!='')return false;
rep(i,y[]+,y[]-)if(a[x[]][i]!='')return false;
rep(i,x[]+,x[]-)rep(j,y[]+,y[]-)if(a[i][j]!='')return false;
return true;
}
int main()
{
int i,j,k,t;
scanf("%d",&n);
rep(i,,n-)scanf("%s",a[i]);
x[]=y[]=inf,x[]=y[]=-;
rep(i,,n-)rep(j,,n-)
if(a[i][j]!='')x[]=min(x[],i),x[]=max(x[],i),y[]=min(y[],j),y[]=max(y[],j);
if(check())puts("Yes");else puts("No");
//system ("pause");
return ;
}
Recover Polygon (easy)的更多相关文章
- oracle_How to Recover Data (Without a Backup!)
How to Recover Data (Without a Backup!) It's the classic career-limiting maneuver(职业限制机动): accidenta ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- [LeetCode] Convex Polygon 凸多边形
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- [LeetCode] Recover Binary Search Tree 复原二叉搜索树
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优
libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...
- 结合谷歌地图多边形(polygon)与Sql Server 2008的空间数据类型计算某个点是否在多边形内的注意事项
首先在利用 GEOGRAPHY::STPolyFromText(@GeoStr, 4326) 这样的函数把字符串转换为Geography类型时,字符串里经纬度的顺序是 “经度[空格]纬度”,即“lon ...
- [svg 翻译教程]Polyline(折线)polygon(多边形)
原文: http://tutorials.jenkov.com/svg/polygon-element.html Polyline 虽然说这个 元素我没用过,但是还是蛮强大的,也翻译下 示例 < ...
- [OpenGL][SharpGL]用Polygon Offset解决z-fighting和stitching问题
[OpenGL][SharpGL]用Polygon Offset解决z-fighting和stitching问题 本文参考了(http://www.zeuscmd.com/tutorials/open ...
- WebGIS中基于AGS的画圆查询简析以及通过Polygon来构造圆的算法
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 某个项目需求中需要在前端进行画圆查询,将圆范围上的多边形要素 ...
随机推荐
- Oracle字符串操作[转:http://www.cnblogs.com/xd502djj/archive/2010/08/11/1797577.html]
ORACLE 字符串操作 1 字符串连接 SQL> select 'abc' || 'def' from dual; 'ABC'|------abcdef 2 小写SQL>select ...
- web开发——水到渠成
1.tomcat中设置编码格式: 打开server.xml,添加下面红色框框里面的内容.
- CSS BFC(Block Formatting Context)
BFC是 W3C CSS 2.1 规范中的一个概念Block Formatting Context的缩写即格式化上下文,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用.简单讲,它是提 ...
- POJ 2239 Selecting Courses
二分图的最大匹配.课程和时间可以看做二分图. #include<cstdio> #include<cstring> #include<cmath> #include ...
- 字符串匹配之boyer-Moore算法
Boyer-Moore算法不仅效率高,而且构思巧妙,容易理解.1977年,德克萨斯大学的Robert S. Boyer教授和J Strother Moore教授发明了这种算法. 下面,我根据Moore ...
- Java中的String[] args
在每个java程序中都有一个方法,public static void main(String[] args)方法,这个参数看了好久没看懂,但是细细看来,还是挺简单的,所有的方法的参数都是一个道理,而 ...
- servlet第1讲初识
- ios小功能
1.开 发过程中,我们通过http请求,后台返回json数据,而有时数据里某一字段的值为null-,然后我们把此值赋值给 NSArray,NSdictionary,或是NSString,然后我们会判断 ...
- linux expr命令参数及用法详解
expr用法 expr命令一般用于整数值,但也可用于字符串.一般格式为: #expr argument operator argument expr也是一个手工命令行计数器. #$expr 10 + ...
- oracle数据库字符集的修改
本文摘自:http://blog.csdn.net/nsj820/article/details/65711051.改客户端字符集:通过WINDOWS的运行菜单运行Regedit,修改注册表 Star ...