UVA 10078 The Art Gallery
Problem:
Century Arts has hundreds of art galleries scattered all around the country and you are hired to write a program that determines whether any of the galleries has a critical point. The galleries are polygonal in shape and a critical point is a point inside that polygon from where the entire gallery is not visible.
Input:
The input file consists of several data blocks. Each data block describes one gallery.
The first line of a data block contains an integer N (3 <= N <= 50) indicating the number of corner points of the gallery. Each of the next N lines contains two integers giving the (x, y) co-ordinates of a corner point where 0 <= x, y <= 1000. Starting from the first point given in the input the corner points occur in the same order on the boundary of the gallery as they appear in the input. No three consecutive points are co-linear.
The input file terminates with a value of 0 for N.
Output:
For each gallery in the input output the word "Yes" if the gallery contains a critical point, otherwise output the word "No". Each output must be on a separate line.
解法:
1:首先可以知道:如果多边形是凸多边形,那么就没有满足题意的这样一个点。所以,我们可以先计算原多边形的面积area1,然后再求凸包,计算凸包的面积area2,如果原多边形是凸多边形,那么area1=area2,否则不相等,这道题就得到了解了。
2:计算原多边形的内核点集及其面积,然后判断这个面积和原多边形的面积是否相等。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
#define exp 1e-10
#define PI 3.141592654
using namespace std;
const int maxn=;
int n,m;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){}
bool friend operator < (Point a,Point b)
{
if (a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
}an[maxn],bn[maxn];
typedef Point Vector;
Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x , A.y+B.y); }
Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x , A.y-B.y); }
Vector operator * (Vector A,double p) {return Vector(A.x*p , A.y*p); }
Vector operator / (Vector A,double p) {return Vector(A.x/p , A.y/p); }
int dcmp(double x) {if (fabs(x)<exp) return ;return x> ? : - ; }
double cross(Vector A,Vector B)
{
return A.x*B.y-B.x*A.y;
}
double get_area(Point *p,int n)
{
double area=;
for (int i= ;i<n ;i++)
area += fabs(cross(p[i]-p[],p[i-]-p[]));
return area;
}
int ConvexHull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
for (int i= ;i<n ;i++)
{
while (m> && dcmp(cross(ch[m-]-ch[m-],p[i]-ch[m-]))<) m--;
ch[m++]=p[i];
}
int k=m;
for (int i=n- ;i>= ;i--)
{
while (m>k && dcmp(cross(ch[m-]-ch[m-],p[i]-ch[m-]))<) m--;
ch[m++]=p[i];
}
if (n>) m--;
return m;
}
int main()
{
while (scanf("%d",&n)!=EOF && n)
{
for (int i= ;i<n ;i++) scanf("%lf%lf",&an[i].x,&an[i].y);
double area1=get_area(an,n);
int k=ConvexHull(an,n,bn);
// cout<<"DEBUG"<<endl;
// for (int i=0 ;i<k ;i++) cout<<an[i].x<<" "<<an[i].y<<endl;
// cout<<"n && k = "<<n<<" "<<k<<endl;
//
double area2=get_area(bn,k);
//cout<<area1<<" **area** "<<area2<<endl;
if (fabs(area1-area2)<exp) printf("No\n");
else printf("Yes\n");
}
return ;
}
UVA 10078 The Art Gallery的更多相关文章
- poj 1279 -- Art Gallery (半平面交)
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- poj 1279 Art Gallery - 求多边形核的面积
/* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...
- 【POJ】【2068】Art Gallery
计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...
- 再来一道测半平面交模板题 Poj1279 Art Gallery
地址:http://poj.org/problem?id=1279 题目: Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- Narrow Art Gallery
Time Limit: 4000ms, Special Time Limit:10000ms, Memory Limit:65536KB Total submit users: 11, Accepte ...
- poj 1279 Art Gallery (Half Plane Intersection)
1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...
- 【POJ 1279】Art Gallery
http://poj.org/problem?id=1279 裸的半平面交的模板,按极角排序后维护一个双端队列,不要忘了最后要去除冗余,即最后一条边(或者更多的边)一定在双端队列里,但它不一定构成半平 ...
- POJ 1279 Art Gallery(半平面交)
题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...
- 【POJ】1279 Art Gallery
http://poj.org/problem?id=1279 题意:给一个n个点的多边形,n<=1500,求在多边形内能看到所有多边形上的点的面积. #include <cstdio> ...
随机推荐
- a标签至于flash之上的时候,IE浏览器无法点击连接的问题
<a style="display: block;height: 131px;position: absolute;z-index: 999;width: 222px;backgrou ...
- ASP.NET MVC5学习笔记之Controller执行ControllerDescriptor和ActionDescriptor
一. ControllerDescriptor说明 ControllerDescriptor是一个抽象类,它定义的接口代码如下: public abstract class ControllerDes ...
- devexpress 数据导入(gridcontrol 导出 csv)
// 1.gridcontrol 导出 csv: DataTable dtbNew = new DataTable(); dtbNew.Columns.Add().GetType()); dtbNew ...
- 十款基础级WordPress插件
1.Akismet插件 Akismet是全球最受欢迎的反垃圾插件,专为对抗"博客spam"."评论spam"而生.Akismet是WordPress官方插件之一 ...
- 转换framebuffer实现安卓截图
编译出了RECOVERY肯定需要截图分享的啦,可是又不能通过DDMS截图~ 那就只好通过提取手机的fb0文件来实现截图. 首先你需要ADB~ 嗯,这个都没有的话你就别看下去了... 还需要ffmpeg ...
- git传输协议原理
git精神:distributed-is-the-new-centralized 转自:http://git-scm.com/book/zh/v1/Git-%E5%86%85%E9%83%A8%E5% ...
- equals函数
equals函数在Object类当中,而Object类是所有类的父类,所以所有的类里面都有equals函数. “==”操作符之前用于比较两个基本数据类型的值是否相等,而对于引用数据类型,“==”操作符 ...
- 非关系型数据库SequoiaDB虚拟机下应用再探
上一次浅谈了SequoiaDB在虚拟机上的安装及在web下图形界面的基本操控,现在来体验命令行操作及运行samples文件. 基本DDL操作 首先在视窗窗口同时按Ctrl+Alt+T,进入到命令行窗口 ...
- windows32位下安装mongodb
下载mongodb:http://downloads.mongodb.org/win32/mongodb-win32-i386-2.4.5.zip 给mongodb指定一个数据存放路径:这里我们放在m ...
- SQLite数据库与Contentprovider(2)
ContentProvider: 在创建ContentProvider时,需要首先使用数据库.文件系统或网络实现底层存储功能, 然后在继承ContentProvider的类中实现基本数据操作的接口函数 ...