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

    转自:https://www.cnblogs.com/gwsbhqt/p/5092390.html 为了能使用上Ntdll.lib库函数,从几份不完整的Ntdll.h中拼凑整理出了比较完整美观的Ntd ...

  2. JS - 迭代协议

    Iteration protocols | MDN 可迭代协议(iterable protocol) 迭代器协议(iterator protocol)

  3. base64编码操作图片

    package com.trsmedia.service; import java.io.FileInputStream; import java.io.FileOutputStream; impor ...

  4. 测开之路七十:监控平台之html

    监控平台的html <!-- 继承base模板 -->{% extends "base.html" %} <!-- 引入bootstrap-datetimepic ...

  5. Vagrant 手册之 box - 创建基础 box

    原文地址 有一种特殊的 box 被称为"base box".这些 box 包含 Vagrant 运作所需的最低限度,通常不是对现有的 Vagrant 环境("base b ...

  6. Java基础复习(1)

    1. Java 基本数据类型 参考博客: https://www.cnblogs.com/LiaHon/p/11043238.html Java语言提供了八种基本类型. 六种数字类型(四个整数型,两个 ...

  7. HeightCharts柱状图和饼状图

    HTML: <div id="container1"  style="height:350px; " ></div>    <di ...

  8. vuejs基础-计算器案例

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. idea2019.1 永久破解 亲测可用

    idea2019突然注册码突然失效了,搜了很多破解办法,这个还是有效的:https://www.jianshu.com/p/b6dd43618a66

  10. Python模块之pdfkit

    1.安装依赖 pip install python-docx #Python下的Microsoft Word 2007工具 pip install PyPDF2 #Python下的PDF工具 pip ...