博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Recover Polygon (easy)
阅读量:5267 次
发布时间:2019-06-14

本文共 3752 字,大约阅读时间需要 12 分钟。

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).

Input

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).

Output

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.

Example
input
6 000000 000000 012100 024200 012100 000000
output
Yes
Note

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 ≤ N0 ≤ y1 < y2 ≤ N), and result in the levels of Zombie Contamination as reported in the input.

分析:四个角是1,边上是2,内部是4,检查一下即可;

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define rep(i,m,n) for(i=m;i<=n;i++)#define rsp(it,s) for(set
::iterator it=s.begin();it!=s.end();it++)#define vi vector
#define pii pair
#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+10;const int dis[4][2]={ { 0,1},{-1,0},{ 0,-1},{ 1,0}};using namespace std;using namespace __gnu_cxx;ll gcd(ll p,ll q){ return q==0?p:gcd(q,p%q);}ll qpow(ll p,ll q){ll f=1;while(q){ if(q&1)f=f*p;p=p*p;q>>=1;}return f;}int n,m,x[2],y[2];char a[maxn][maxn];bool check(){ int i,j; rep(i,0,1)rep(j,0,1)if(a[x[i]][y[i]]!='1')return false; rep(i,x[0]+1,x[1]-1)if(a[i][y[0]]!='2')return false; rep(i,x[0]+1,x[1]-1)if(a[i][y[1]]!='2')return false; rep(i,y[0]+1,y[1]-1)if(a[x[0]][i]!='2')return false; rep(i,y[0]+1,y[1]-1)if(a[x[1]][i]!='2')return false; rep(i,x[0]+1,x[1]-1)rep(j,y[0]+1,y[1]-1)if(a[i][j]!='4')return false; return true;}int main(){ int i,j,k,t; scanf("%d",&n); rep(i,0,n-1)scanf("%s",a[i]); x[0]=y[0]=inf,x[1]=y[1]=-1; rep(i,0,n-1)rep(j,0,n-1) if(a[i][j]!='0')x[0]=min(x[0],i),x[1]=max(x[1],i),y[0]=min(y[0],j),y[1]=max(y[1],j); if(check())puts("Yes");else puts("No"); //system ("pause"); return 0;}

 

转载于:https://www.cnblogs.com/dyzll/p/5668701.html

你可能感兴趣的文章
MySQL 字符编码问题详细解释
查看>>
Ubuntu下面安装eclipse for c++
查看>>
让IE浏览器支持CSS3圆角属性的方法
查看>>
巡风源码阅读与分析---nascan.py
查看>>
LiveBinding应用 dataBind 数据绑定
查看>>
Linux重定向: > 和 &> 区别
查看>>
nginx修改内核参数
查看>>
C 筛选法找素数
查看>>
TCP为什么需要3次握手与4次挥手(转载)
查看>>
IOC容器
查看>>
Windows 2003全面优化
查看>>
URAL 1002 Phone Numbers(KMP+最短路orDP)
查看>>
web_day4_css_宽度
查看>>
electron入门心得
查看>>
格而知之2:UIView的autoresizingMask属性探究
查看>>
我的Hook学习笔记
查看>>
js中的try/catch
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
简述spring中常有的几种advice?
查看>>
整理推荐的CSS属性书写顺序
查看>>