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 (xy) co-ordinates of a corner point where 0 <= xy <= 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的更多相关文章

  1. poj 1279 -- Art Gallery (半平面交)

    鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  2. poj 1279 Art Gallery - 求多边形核的面积

    /* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...

  3. 【POJ】【2068】Art Gallery

    计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...

  4. 再来一道测半平面交模板题 Poj1279 Art Gallery

    地址:http://poj.org/problem?id=1279 题目: Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  5. Narrow Art Gallery

    Time Limit: 4000ms, Special Time Limit:10000ms, Memory Limit:65536KB Total submit users: 11, Accepte ...

  6. poj 1279 Art Gallery (Half Plane Intersection)

    1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...

  7. 【POJ 1279】Art Gallery

    http://poj.org/problem?id=1279 裸的半平面交的模板,按极角排序后维护一个双端队列,不要忘了最后要去除冗余,即最后一条边(或者更多的边)一定在双端队列里,但它不一定构成半平 ...

  8. POJ 1279 Art Gallery(半平面交)

    题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...

  9. 【POJ】1279 Art Gallery

    http://poj.org/problem?id=1279 题意:给一个n个点的多边形,n<=1500,求在多边形内能看到所有多边形上的点的面积. #include <cstdio> ...

随机推荐

  1. Spark自定义分区(Partitioner)

    我们都知道Spark内部提供了HashPartitioner和RangePartitioner两种分区策略,这两种分区策略在很多情况下都适合我们的场景.但是有些情况下,Spark内部不能符合咱们的需求 ...

  2. MySQL的相关概念介绍

    MySQL 为关系型数据库(Relational Database Management System), 这种所谓的"关系型"可以理解为"表格"的概念, 一个 ...

  3. Ueditor图片缩放的设置

    最近在用Ueditor,功能绝逼强大,不过也有遗憾的地方,上传图片的时候自动缩放的小了,想要图片按宽度整体等比缩放,找了好久,研究了下,终于找到解决方法了. 先改前台的的dialogs/image/i ...

  4. js给php传值

    //ajax传值 var str= JSON.stringify(arr1);//数组转string //alert(typeof(str)); $.ajax({ url:'test.php' ,ty ...

  5. php中的日期

    1.在PHP中获取日期和时间 time()返回当前时间的 Unix 时间戳. getDate()返回日期/时间信息. gettimeofday()返回当前时间信息.date_sunrise()返回给定 ...

  6. SQL Server 锁表、查询被锁表、解锁相关语句

    SQL Server 锁表.查询被锁表.解锁相关语句,供参考. --锁表(其它事务不能读.更新.删除) BEGIN TRAN SELECT * FROM <表名> WITH(TABLOCK ...

  7. 小课堂week15 年终小结

    年终小结 一年的最后,想和大家回顾一下今年讲过的技术和书,用一些问答,一起来提炼一下精华. Spark 为什么需要分布式计算? 计算的增长速度超过了硬件的增长,单一服务器无法负荷.多服务器带来的是复杂 ...

  8. Linux学习-0626

    6.26 Linux的安装1.下载镜像包.iso,启动时设置光盘的包是安装包,就可以看到完成安装流程 安装CentOS 5.52.安装时分区,swap分区,根分区... Linux管理工具:1.Sec ...

  9. ED/EP系列5《消费指令》

    1. 消费交易 消费交易允许持卡人使用电子存折或电子钱包的余额进行购物或获取服务. 特点: 1) --可以在销售点终端(POS)上脱机进行 2) --使用电子存折进行的消费交易必须提交个人识别码(PI ...

  10. 解惑:NFC手机如何轻松读取银行卡信息?

    自支付宝钱包8.0推出了NFC新功能,只要将支持NFC功能的手机靠近公交卡.银行卡等带有芯片的IC卡上,可迅速读取卡内余额.卡的信息,还可以给卡进行充值,非常贴心实用. 但是很多网友表示担忧,要是别人 ...