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. winform自动添加同级目录下可执行文件的快捷方式到右键菜单中

    /// <summary> /// 追加同目录下可执行文件到右键菜单中 /// 在form的Load事件中调用:new clsContextMenuStrip(this.FindForm( ...

  2. [leetcode]_Remove Duplicates from Sorted Array II

    题目:一个有序数组,要求保证数组中的每个元素不能超过2个.  输入:A = [1,1,1,2,2,3]  输出:length = 5, and A is now [1,1,2,2,3] 思路:双指针 ...

  3. 火狐浏览器设置placeholder的时候记得改opacity

    最近做项目的时候涉及到需要修改输入框的placeholder的字体颜色,我的CSS如下: ::-webkit-input-placeholder{ color: #c5c5c5;}::-moz-pla ...

  4. luigi学习2-在hadoop上运行Top Artists

    一.AggregateArtistsHadoop class AggregateArtistsHadoop(luigi.contrib.hadoop.JobTask): date_interval = ...

  5. sqoop简单import使用

    一.sqoop作用? sqoop是一个数据交换工具,最常用的两个工具是导入导出. 导入导出的参照物是hadoop,向hadoop导数据就是导入. 二.sqoop的版本? sqoop目前有两个版本,1. ...

  6. Mongod(5):启动命令mongod参数说明

    Mongodb启动命令mongod参数说明(http://blog.csdn.net/fdipzone/article/details/7442162) mongod的主要参数有: 基本配置 ---- ...

  7. AeroSpike 资料

    文档总览:http://www.aerospike.com/docs/ JAVA AeroSpike知识总览:http://www.aerospike.com/docs/client/java/sta ...

  8. mysql中的 IN和FIND_IN_SET的查询问题

    原来以为mysql可以进行这样的查询select id, list, name from table where 'daodao' IN (list);      (一)注:1. table含有三个字 ...

  9. lua进阶(一)

    第一章 概览     1.chunks              chunks是一系列语句, lua执行的每一块语句,比如一个文件或者交互模式下的每一行都是一个chunks.      2.全局变量 ...

  10. C#使用SQL存储过程完整流程

    存储过程就是固化在SQL数据库系统内部的SQL语句,这样做的好处是可以提高执行效率.提高数据库的安全性.减少网络流量.接下来就讲解如何在数据库中建立一个存储过程. 打开SQL2055数据库,展开“数据 ...