poj 3130 How I Mathematician Wonder What You Are! (半平面交)

原创 2017年01月03日 08:55:48

How I Mathematician Wonder What You Are!
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 3668   Accepted: 1977

Description

After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician uses a big astronomical telescope and lets his image processing program count stars. The hardest part of the program is to judge if shining object in the sky is really a star. As a mathematician, the only way he knows is to apply a mathematical definition of stars.

The mathematical definition of a star shape is as follows: A planar shape F is star-shaped if and only if there is a point C ∈ F such that, for any point P ∈ F, the line segment CP is contained in F. Such a point C is called a center of F. To get accustomed to the definition let’s see some examples below.

The first two are what you would normally call stars. According to the above definition, however, all shapes in the first row are star-shaped. The two in the second row are not. For each star shape, a center is indicated with a dot. Note that a star shape in general has infinitely many centers. Fore Example, for the third quadrangular shape, all points in it are centers.

Your job is to write a program that tells whether a given polygonal shape is star-shaped or not.

Input

The input is a sequence of datasets followed by a line containing a single zero. Each dataset specifies a polygon, and is formatted as follows.

n  
x1 y1
x2 y2

xn yn

The first line is the number of vertices, n, which satisfies 4 ≤ n ≤ 50. Subsequent n lines are the x- and y-coordinates of the n vertices. They are integers and satisfy 0 ≤ xi ≤ 10000 and 0 ≤ yi ≤ 10000 (i = 1, …, n). Line segments (xiyi)–(xi + 1yi + 1) (i = 1, …, n − 1) and the line segment (xnyn)–(x1y1) form the border of the polygon in the counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions.

You may assume that the polygon is simple, that is, its border never crosses or touches itself. You may assume assume that no three edges of the polygon meet at a single point even when they are infinitely extended.

Output

For each dataset, output “1” if the polygon is star-shaped and “0” otherwise. Each number must be in a separate line and the line should not contain any other characters.

Sample Input

6 
66 13 
96 61 
76 98 
13 94 
4 0 
45 68 
8 
27 21 
55 14 
93 12 
56 95 
15 48 
38 46 
51 65 
64 31 
0

Sample Output

1
0

Source

[Submit]   [Go Back]   [Status]   [Discuss]


题目大意:判断多边形是否有内核

题解:半平面交

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 100
#define eps 1e-8
#define inf 1000000
using namespace std;
struct vector {
	double x,y;
	vector (double X=0,double Y=0){
		x=X,y=Y;
	}
}a[N],p[N];
int n,m;
typedef vector point;
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 t){
	return vector (a.x*t,a.y*t);
}
void init()
{
	m=0;
	p[m++]=point(inf,inf);
	p[m++]=point(-inf,inf);
	p[m++]=point(-inf,-inf);
	p[m++]=point(inf,-inf);
}
double cross(vector a,vector b){
	return a.x*b.y-a.y*b.x;
}
point glt(point a,point a1,point b,point b1)
{
	vector v=a1-a; vector w=b1-b;
	vector u=a-b;
	double t=cross(w,u)/cross(v,w);
	return a+v*t;
}
void cut(point a,point b)
{
	point tmp[N];
	int cnt=0;
	for (int i=0;i<m;i++){
		double c=cross(b-a,p[i]-a);
		double d=cross(b-a,p[(i+1)%m]-a);
		if (c<=0) tmp[cnt++]=p[i];
		if (c*d<0)
		 tmp[cnt++]=glt(a,b,p[i],p[(i+1)%m]);
	}
	m=cnt;
	for (int i=0;i<cnt;i++) p[i]=tmp[i];
}
int main()
{
	freopen("a.in","r",stdin);
	while (true){
		scanf("%d",&n);
		if (!n) break;
		for (int i=1;i<=n;i++)
		 scanf("%lf%lf",&a[i].x,&a[i].y);
		init();
		a[n+1]=a[1];
		for (int i=2;i<=n+1;i++){
			cut(a[i],a[i-1]);
			if (!m) break;
		}
		if (m) printf("1\n");
		else printf("0\n");
	}
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3130-How I Mathematician Wonder What You Are!(计算几何-星形-半平面交逆时针模板)

How I Mathematician Wonder What You Are! Time Limit: 5000MS   Memory Limit: 65536K T...
  • MIKASA3
  • MIKASA3
  • 2017年04月16日 20:41
  • 317

半平面交初级

半平面:顾名思义,半平面就是平面的一半,那么半平面应该如何表示呢?我们知道一条直线可以将平面分成两半,如果直线的方程为ax+by+c=0ax+by+c = 0,那么半平面就可以表示为ax+by+c0a...
  • huayunhualuo
  • huayunhualuo
  • 2016年04月15日 20:15
  • 794

半平面交总结and模板

这两天刷了POJ上几道半平面交,对半平面交有了初步的体会,感觉半平面交还是个挺实用的知识点。 半平面交主要是看的ZZY的国家队论文,他提出的是一种O(n×log(n))的排序增量法。 附论文地址: 算...
  • xuechelingxiao
  • xuechelingxiao
  • 2014年11月06日 16:44
  • 2574

计算几何学习之半平面交

首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分为两个部分,那么这两个部分就叫做两个半平面。 然后,半平面怎么表示呢? 二维坐标系下,直线可以表示为...
  • kep159
  • kep159
  • 2014年04月22日 15:51
  • 985

poj1279Art Gallery【半平面交求内核面积】

Language: Default Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Su...
  • R1986799047
  • R1986799047
  • 2015年09月14日 23:45
  • 618

poj1755Triathlon【半平面交】

Language: Default Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Subm...
  • R1986799047
  • R1986799047
  • 2015年09月20日 01:22
  • 455

POJ 2451 nlog(n)半平面交裸题。

Uyuw's Concert Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 6587   ...
  • u012358934
  • u012358934
  • 2014年05月04日 18:44
  • 971

【半平面交】[ZJOI2008][HYSBZ\BZOJ1038]瞭望塔

题目链接分析看穿题目考虑组成村庄的每一条线段,显然,我们要在这条线段所在直线上方的半平面内才能看见它。所以,瞭望塔必须要在所有组成村庄的线段的所在直线的上方的半平面的交集内,才能 从瞭望塔的顶端可...
  • outer_form
  • outer_form
  • 2016年02月05日 17:37
  • 413

HDU 2297 半平面交

Run Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub...
  • u012358934
  • u012358934
  • 2014年05月15日 17:28
  • 1203

[半平面交对偶凸包] BZOJ 1007 [HNOI2008]水平可见直线

半平面交对偶转凸包问题 神奇的新姿势 还有待研究#include #include #include using namespace std; typedef long long ll;inline...
  • u014609452
  • u014609452
  • 2017年02月14日 10:28
  • 186
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 3130 How I Mathematician Wonder What You Are! (半平面交)
举报原因:
原因补充:

(最多只允许输入30个字)