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. 利用JS实现的根据经纬度计算地球上两点之间的距离

      最近用到了根据经纬度计算地球表面两点间距离的公式,然后就用JS实现了一下. 计算地球表面两点间的距离大概有两种办法. 第一种是默认地球是一个光滑的球面,然后计算任意两点间的距离,这个距离叫做大圆距 ...

  2. PHP截取字符串 兼容utf-8 gb2312

    <?php function subString($string,$length,$append = false) { if(strlen($string) <= $length ) { ...

  3. [Linux]Nginx + Node.js + PM2 + MongoDb + (Memcached) Part I

    运行环境: 在本地的VirtualBox下运行的Ubuntu 14.04 LTS  0. 查看一下Server的IP地址 ifconfig 我的Server IP是192.168.0.108 1. 安 ...

  4. 禁止 PC端打开网页 进行跳转

    try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")){if ((navigator.user ...

  5. PHP 简单实现MySQL数据搜索、添加数据功能 以设备管理为例

    测试截图: 数据库bzec ,表shebeidangan 列sb_name,sb_numandtype,sb_home,sb_usedate,sb_address,sb_updatetime,sb_r ...

  6. 解决matplotlib中文乱码问题(Windows)

    1.修改matplotlibrc文件 进入Python安装目录下的Lib\site-packages\matplotlib\mpl-data目录,打开matplotlibrc文件,删除font.fam ...

  7. meteor 实现 微信分享

    Template.hello.events({ 'click button': function () { // increment the counter when button is clicke ...

  8. 主要从架构上来做优化,负载均衡、CDN、静态化、数据库的水平切割和纵向切割、读写分离、分布式缓存着手

    语言知识一种工具,甚至技术本身也只是一种工具,本身并不值钱,关键在于用于何种行业,产生了什么价值. 但从语言来看,我个人更喜欢php,然后是C#,然后是java从框架而言,先是java,然后C#,再次 ...

  9. 深入浅出Spring(五) SpringMVC

    上一篇深入浅出Spring(四) Spring实例分析的博文中,咱们已经可以了解Spring框架的运行原理和实现过程,接下来咱们继续讲解Spring的一个延伸产品——Spring MVC 1.Spri ...

  10. UISegmentedControl swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...