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 ≤ 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)的更多相关文章

  1. oracle_How to Recover Data (Without a Backup!)

    How to Recover Data (Without a Backup!) It's the classic career-limiting maneuver(职业限制机动): accidenta ...

  2. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  3. [LeetCode] Convex Polygon 凸多边形

    Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...

  4. [LeetCode] Recover Binary Search Tree 复原二叉搜索树

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  5. 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优

    libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...

  6. 结合谷歌地图多边形(polygon)与Sql Server 2008的空间数据类型计算某个点是否在多边形内的注意事项

    首先在利用 GEOGRAPHY::STPolyFromText(@GeoStr, 4326) 这样的函数把字符串转换为Geography类型时,字符串里经纬度的顺序是 “经度[空格]纬度”,即“lon ...

  7. [svg 翻译教程]Polyline(折线)polygon(多边形)

    原文: http://tutorials.jenkov.com/svg/polygon-element.html Polyline 虽然说这个 元素我没用过,但是还是蛮强大的,也翻译下 示例 < ...

  8. [OpenGL][SharpGL]用Polygon Offset解决z-fighting和stitching问题

    [OpenGL][SharpGL]用Polygon Offset解决z-fighting和stitching问题 本文参考了(http://www.zeuscmd.com/tutorials/open ...

  9. WebGIS中基于AGS的画圆查询简析以及通过Polygon来构造圆的算法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 某个项目需求中需要在前端进行画圆查询,将圆范围上的多边形要素 ...

随机推荐

  1. yaf for ubuntu安装

    一.安装yaf需要的扩展 apt-get install perl-modules apt-get install libpcrecpp0 apt-get install libpcre3 libpc ...

  2. 使用 VirtualBox 虚拟机在电脑上运行 Android 4.0 系统,让电脑瞬间变安卓平板

    Ref: http://www.iplaysoft.com/android-v4-ics-for-virtualbox.html 随着 Android 手机的各种软件应用越来越多,很多没有购买的朋友都 ...

  3. android命令行网络时间同步

    一.简介 Android基于Linux平台的开源手机操作系统. 二.原理 既然是Linux,那就应该支持linux的各种命令行,高度的可配置,但实验发现Android是Google的一个高度阉割版的l ...

  4. Unity3d之将terrain转化成mesh

    Unity3d中,terrain还是比较耗的,DrawCall数也比较多,为了优化性能,可能需要将terrain转化成mesh. 现提供一工具,思路是根据terrain高度图生成mesh等,可参考:  ...

  5. ASP.NET弹出提示点击确定之后再跳转页面的方法

    //ASP.NET弹出提示点击确定之后再跳转页面的方法 //弹出了提示并且通过location.href转到了DeskTop.aspx页面 Response.Write("<scrip ...

  6. git 忽略已跟踪的文件

    对于未跟踪的文件,可以编辑.gitignore文件进行忽略. 对于已跟踪的文件,编辑.gitignore文件不会起作用,它只针对未被跟踪的文件,也就是你先设置规则,然后添加的新文件符合这些规则的就会被 ...

  7. iOS长按选择

    确实,其实就是一个长按手势 + 图片二维码识别,原生SDK从8.0开始支持 /** *  从照片中直接识别二维码 *  @param qrCodeImage 带二维码的图片 *  @param myQ ...

  8. iOS中date和string的相互转换

    必须知道的内容 G: 公元时代,例如AD公元     yy: 年的后2位     yyyy: 完整年     MM: 月,显示为1-12     MMM: 月,显示为英文月份简写,如 Jan      ...

  9. Razor Engine,动态脚本语言,mvc上的语法,适用于文件内容生成,静态网页生成等。

    https://razorengine.codeplex.com/ 下载并引用:razorengine.dll 代码里这样写,用mvc的人都会!Razor语法! string template = & ...

  10. Hibernate写入Oracle Date类型处理

    Hibernate写入Oracle数据库时,数据库设计字段为Date类型时,只能保存年月日,不能保存时分秒,如果要保存时分秒,需修改Hibernate.cfg.xml文件 <property n ...