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.

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.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.

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 这两个题,都是输入一个简单多边形,判断是否存在核,套半平面交模版即可。
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; const double eps = 1e-;
const int maxn = ; int dq[maxn], top, bot, pn, order[maxn], ln;
struct Point {
double x, y;
} p[maxn]; struct Line {
Point a, b;
double angle;
} l[maxn]; int dblcmp(double k) {
if (fabs(k) < eps) return ;
return k > ? : -;
} double multi(Point p0, Point p1, Point p2) {
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
} bool cmp(int u, int v) {
int d = dblcmp(l[u].angle-l[v].angle);
if (!d) return dblcmp(multi(l[u].a, l[v].a, l[v].b)) > ; //大于0取向量左半部分为半平面,小于0,取右半部分
return d < ;
} void getIntersect(Line l1, Line l2, Point& p) {
double dot1,dot2;
dot1 = multi(l2.a, l1.b, l1.a);
dot2 = multi(l1.b, l2.b, l1.a);
p.x = (l2.a.x * dot2 + l2.b.x * dot1) / (dot2 + dot1);
p.y = (l2.a.y * dot2 + l2.b.y * dot1) / (dot2 + dot1);
} bool judge(Line l0, Line l1, Line l2) {
Point p;
getIntersect(l1, l2, p);
return dblcmp(multi(p, l0.a, l0.b)) < ; //大于小于符号与上面cmp()中注释处相反
} void addLine(double x1, double y1, double x2, double y2) {
l[ln].a.x = x1; l[ln].a.y = y1;
l[ln].b.x = x2; l[ln].b.y = y2;
l[ln].angle = atan2(y2-y1, x2-x1);
order[ln] = ln;
ln++;
} void halfPlaneIntersection() {
int i, j;
sort(order, order+ln, cmp);
for (i = , j = ; i < ln; i++)
if (dblcmp(l[order[i]].angle-l[order[j]].angle) > )
order[++j] = order[i];
ln = j + ;
dq[] = order[];
dq[] = order[];
bot = ;
top = ;
for (i = ; i < ln; i++) {
while (bot < top && judge(l[order[i]], l[dq[top-]], l[dq[top]])) top--;
while (bot < top && judge(l[order[i]], l[dq[bot+]], l[dq[bot]])) bot++;
dq[++top] = order[i];
}
while (bot < top && judge(l[dq[bot]], l[dq[top-]], l[dq[top]])) top--;
while (bot < top && judge(l[dq[top]], l[dq[bot+]], l[dq[bot]])) bot++;
} bool isThereACore() {
if (top-bot > ) return true;
return false;
} int main()
{
//freopen("de.txt","r",stdin);
int i;
while (scanf ("%d", &pn) && pn) {
for (i = ; i < pn; i++)
scanf ("%lf%lf", &p[i].x, &p[i].y);
for (ln = i = ; i < pn-; i++)
addLine(p[i].x, p[i].y, p[i+].x, p[i+].y);
addLine(p[i].x, p[i].y, p[].x, p[].y);
halfPlaneIntersection();
/*输出这个核
Point poly[55];
int k = 0;
for (int i=bot;i<=top;++i)
poly[k++] = p[i];
for (int i=bot;i<=top;++i)
printf("%.3f %.3f\n",poly[i].x,poly[i].y);
*/
if (isThereACore()) printf ("1\n");
else printf ("0\n");
}
return ;
}
 

POJ 3130 How I Mathematician Wonder What You Are! (半平面相交)的更多相关文章

  1. POJ 3130 How I Mathematician Wonder What You Are! (半平面交)

    题目链接:POJ 3130 Problem Description After counting so many stars in the sky in his childhood, Isaac, n ...

  2. poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版

    /* poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 */ #include <stdio.h> #include ...

  3. POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交

    题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...

  4. poj 3130 How I Mathematician Wonder What You Are!

    http://poj.org/problem?id=3130 #include <cstdio> #include <cstring> #include <algorit ...

  5. POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)

    题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...

  6. poj 3130 How I Mathematician Wonder What You Are! 【半平面交】

    求多边形的核,直接把所有边求半平面交判断有无即可 #include<iostream> #include<cstdio> #include<algorithm> # ...

  7. 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130

    求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...

  8. How I Mathematician Wonder What You Are! - POJ 3130(求多边形的核)

    题目大意:判断多多边形是否存在内核. 代码如下: #include<iostream> #include<string.h> #include<stdio.h> # ...

  9. How I Mathematician Wonder What You Are!(poj 3130)

    题意:求问多边形的核(能够看到所有点的点)是否存在. /* 对于这样的题目,我只能面向std编程了,然而还是不理解. 算法可参考:http://www.cnblogs.com/huangxf/p/40 ...

随机推荐

  1. DHCP原理

    一台主机的ip地址可用通过两种方式来设置.1 手动输入:2 自动向DHCP服务器获取.手动输入会出现错误,比如输入一个已经分配的ip地址,当内网机器只有几台,十几台还可以忍受,如果是几百台呢,不可能一 ...

  2. 小程序页面间传值(处理传值为对象,简单传值直接用options.XX的形式获取)

    bookgoods:function(){ var Json = JSON.stringify(this.data.goods) wx.navigateTo({ url: '/pages/bookgo ...

  3. 接口自动化之cookies登录

    现在有很多网站有验证码,跳过验证码实现登录可以使用cookies登录 目录 1.requests的添加cookies的方法 2.举个栗子 1.requests的添加cookies的方法 request ...

  4. IAR MSP430怎么破解?IAR for MSP430安装注册破解激活图文详细教程

      IAR for MSP430全称IAR Embedded Workbench for MSP430,是一款功能强大的专业集成开发环境,软件包括项目管理.配置开发环境.创建编译器.定制具体编程方案等 ...

  5. IDEA activate-power-mode插件

    一 下载activate-power-mode插件 方法1:插件库下载: 地址:http://plugins.jetbrains.com/plugin/8330-activate-power-mode ...

  6. 网络流强化-HDU4280

    数组没开够居然显示TLE而不是RE,自己觉得好的优化的方法没什么用…… //http://www.renfei.org/blog/isap.html 带解释的 //https://www.cnblog ...

  7. jQuery遍历集合

     jQuery 遍历List集合 $(function(){ var tbody = ""; var obj =[{"name ":"xxxx&quo ...

  8. SAP选择屏幕开发(一)(转)

    原文链接:https://blog.csdn.net/wtxhai/article/details/90632686 用户通过屏幕操作来实现与SAP的数据交互,而SAP的屏幕开发一般分为两种,一种是通 ...

  9. shuoj 1 + 2 = 3? (二分+数位dp)

    题目传送门 1 + 2 = 3? 发布时间: 2018年4月15日 22:46   最后更新: 2018年4月15日 23:25   时间限制: 1000ms   内存限制: 128M 描述 埃森哲是 ...

  10. 75.Binary Tree Maximum Path Sum(二叉树的最大路径和)

    Level:   Hard 题目描述: Given a non-empty binary tree, find the maximum path sum. For this problem, a pa ...