/*
poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 */
#include <stdio.h>
#include<math.h>
const double eps=1e-8;
const int N=103;
struct point
{
double x,y;
}dian[N];
inline bool mo_ee(double x,double y)
{
double ret=x-y;
if(ret<0) ret=-ret;
if(ret<eps) return 1;
return 0;
}
inline bool mo_gg(double x,double y) { return x > y + eps;} // x > y
inline bool mo_ll(double x,double y) { return x < y - eps;} // x < y
inline bool mo_ge(double x,double y) { return x > y - eps;} // x >= y
inline bool mo_le(double x,double y) { return x < y + eps;} // x <= y
inline double mo_xmult(point p2,point p0,point p1)//p1在p2左返回负,在右边返回正
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} point mo_intersection(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
}
///////////////////////// //切割法求半平面交
point mo_banjiao_jiao[N*2];
point mo_banjiao_jiao_temp[N*2];
void mo_banjiao_cut(point *ans,point qian,point hou,int &nofdian)
{
int i,k;
for(i=k=0;i<nofdian;++i)
{
double a,b;
a=mo_xmult(hou,ans[i],qian);
b=mo_xmult(hou,ans[(i+1)%nofdian],qian);
if(mo_ge(a,0))//顺时针就是<=0
{
mo_banjiao_jiao_temp[k++]=ans[i];
}if(mo_ll(a*b,0))
{
mo_banjiao_jiao_temp[k++]=mo_intersection(qian,hou,ans[i],ans[(i+1)%nofdian]);
}
}
for(i=0;i<k;++i)
{
ans[i]=mo_banjiao_jiao_temp[i];
}
nofdian=k;
}
int mo_banjiao(point *dian,int n)
{
int i,nofdian;
nofdian=n;
for(i=0;i<n;++i)
{
mo_banjiao_jiao[i]=dian[i];
}
for(i=0;i<n;++i)//i从0开始
{
mo_banjiao_cut(mo_banjiao_jiao,dian[i],dian[(i+1)%n],nofdian);
if(nofdian==0)
{
return nofdian;
}
}
return nofdian;
}
/////////////////////////
int main()
{
int t,i,n;
while(scanf("%d",&n),n)
{ for(i=0;i<n;++i)
{
scanf("%lf%lf",&dian[i].x,&dian[i].y);
}
int ret=mo_banjiao(dian,n);
if(ret==0)
{
printf("0\n");
}else
{
printf("1\n");
}
}
return 0;
}
/*
为什么ret<3?
*/
#include<stdio.h>
#include<math.h>
#include <algorithm>
using namespace std; const double eps=1e-8;
struct point
{
double x,y;
}dian[20000+10];
point jiao[203];
struct line
{
point s,e;
double angle;
}xian[20000+10];
int n,yong;
bool mo_ee(double x,double y)
{
double ret=x-y;
if(ret<0) ret=-ret;
if(ret<eps) return 1;
return 0;
}
bool mo_gg(double x,double y) { return x > y + eps;} // x > y
bool mo_ll(double x,double y) { return x < y - eps;} // x < y
bool mo_ge(double x,double y) { return x > y - eps;} // x >= y
bool mo_le(double x,double y) { return x < y + eps;} // x <= y
point mo_intersection(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
}
double mo_xmult(point p2,point p0,point p1)//p1在p2左返回负,在右边返回正
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} void mo_HPI_addl(point a,point b)
{
xian[yong].s=a;
xian[yong].e=b;
xian[yong].angle=atan2(b.y-a.y,b.x-a.x);
yong++;
}
//半平面交
bool mo_HPI_cmp(const line& a,const line& b)
{
if(mo_ee(a.angle,b.angle))
{
return mo_gg( mo_xmult(b.e,a.s,b.s),0);
}else
{
return mo_ll(a.angle,b.angle);
}
}
int mo_HPI_dq[20000+10];
bool mo_HPI_isout(line cur,line top,line top_1)
{
point jiao=mo_intersection(top.s,top.e,top_1.s,top_1.e);
return mo_ll( mo_xmult(cur.e,jiao,cur.s),0);//若顺时针时应为mo_gg
}
int mo_HalfPlaneIntersect(line *xian,int n,point *jiao)
{
int i,j,ret=0;
sort(xian,xian+n,mo_HPI_cmp);
for (i = 0, j = 0; i < n; i++)
{
if (mo_gg(xian[i].angle,xian[j].angle))
{
xian[++j] = xian[i];
}
}
n=j+1;
mo_HPI_dq[0]=0;
mo_HPI_dq[1]=1;
int top=1,bot=0;
for (i = 2; i < n; i++)
{
while (top > bot && mo_HPI_isout(xian[i], xian[mo_HPI_dq[top]], xian[mo_HPI_dq[top-1]])) top--;
while (top > bot && mo_HPI_isout(xian[i], xian[mo_HPI_dq[bot]], xian[mo_HPI_dq[bot+1]])) bot++;
mo_HPI_dq[++top] = i; //当前半平面入栈
}
while (top > bot && mo_HPI_isout(xian[mo_HPI_dq[bot]], xian[mo_HPI_dq[top]], xian[mo_HPI_dq[top-1]])) top--;
while (top > bot && mo_HPI_isout(xian[mo_HPI_dq[top]], xian[mo_HPI_dq[bot]], xian[mo_HPI_dq[bot+1]])) bot++;
mo_HPI_dq[++top] = mo_HPI_dq[bot];
for (ret = 0, i = bot; i < top; i++, ret++)
{
jiao[ret]=mo_intersection(xian[mo_HPI_dq[i+1]].s,xian[mo_HPI_dq[i+1]].e,xian[mo_HPI_dq[i]].s,xian[mo_HPI_dq[i]].e);
}
return ret;
}
int main()
{
int i;
while(scanf("%d",&n),n)
{
yong=0;
for(i=0;i<n;++i)
{
scanf("%lf%lf",&dian[i].x,&dian[i].y);
}
for(i=0;i<n;++i)
{
mo_HPI_addl(dian[i],dian[(i+1)%n]);
}
int ret=mo_HalfPlaneIntersect(xian,n,jiao);
if(ret<3)
{
printf("0\n");
}else
{
printf("1\n");
}
}
return 0;
}

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 3335 Rotating Scoreboard 初涉半平面交

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

  3. poj 1474 Video Surveillance - 求多边形有没有核

    /* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...

  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! (半平面相交)

    Description After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a ...

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

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

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

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

  8. POJ 1279 Art Gallery【半平面交】(求多边形的核)(模板题)

    <题目链接> 题目大意: 按顺时针顺序给出一个N边形,求N边形的核的面积. (多边形的核:它是平面简单多边形的核是该多边形内部的一个点集该点集中任意一点与多边形边界上一点的连线都处于这个多 ...

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

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

随机推荐

  1. C#窗口矩形区域着色

    C#写的一个GUI窗口,有几百个矩形区域.每个矩形区域的颜色随时都可能改变,并且多次改变. 我放弃使用label绘制矩形,因为效果不好.拖控件的界面使用power packs中的rectanglesh ...

  2. angular.js 验证码注册登录

    css部分 header{ height: 50px; line-height: 50px; display: flex; } .callback{ text-align: left; display ...

  3. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E - Goods transportation 最大流转最小割转dp

    E - Goods transportation 思路:这个最大流-> 最小割->dp好巧妙哦. #include<bits/stdc++.h> #define LL long ...

  4. Codeforces Round #371 (Div. 1) D - Animals and Puzzle 二维ST表 + 二分

    D - Animals and Puzzle #include<bits/stdc++.h> #define LL long long #define fi first #define s ...

  5. 牛客练习赛19 D-托米去购物

    最裸的最大流,没啥好说的.. #include<bits/stdc++.h> #define LL long long #define fi first #define se second ...

  6. Windows 命令行切换目录

    Windows 命令行切换目录 特别注意:切换到其它盘符不需要 cd 命令 1. 切换到 C 盘根目录 打开终端 cmd 后,输入cd C:\(一定要加上后面的反斜扛) 2.切换到 C 盘子目录 打开 ...

  7. 9 行 javascript 代码获取 QQ 群成员

    昨天看到一条微博:「22 行 JavaScript 代码实现 QQ 群成员提取器」. 本着好奇心点击进去,发现没有达到效果,一是 QQ 版本升级了,二是博客里面的代码也有些繁琐. 于是自己试着写了一个 ...

  8. windbg调试相关命令

    windbg 查找函数:x exe!main* 条件断点打印字符:bp 7199a2b0 ".printf \"message:%ma\", poi(@esp+8);.e ...

  9. 20179202《Linux内核原理与分析》第一周作业

    实验一 Linux 系统简介 这一节主要学习了Linux的历史,重要人物以及学习Linux的方法.Linux和Windows在是否收费.软件与支持.安全性.可定制性和应用范畴等方面都存在着区别.目前感 ...

  10. hihocoder 1490 Tree Restoration

    构造. 从最后一层开始往上构造.最后一层肯定都是叶子结点,距离为2的肯定是同一个父亲,确定好了父亲之后,可以确定上一层每个节点之间的距离,以及上一层每个节点到还未确定的叶子节点之间的距离. #incl ...