求多边形的核,直接把所有边求半平面交判断有无即可

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=205;
const double eps=1e-6;
int n;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a)
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a)
{
return dian(x-a.x,y-a.y);
}
dian operator * (const double &a) const
{
return dian(x*a,y*a);
}
dian operator / (const double &a) const
{
return dian(x/a,y/a);
}
}p[N];
struct bian
{
dian s,v;
bian(dian S=dian(),dian V=dian())
{
s=S,v=V;
}
}l[N],s[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
double mj(dian a,dian b,dian c)
{
return cj(b-a,c-a)/2;
}
dian jd(bian x,bian y)
{
return x.s+x.v*(cj(x.s-y.s,y.v)/cj(y.v,x.v));
}
bool px(bian a,bian b)
{
return cj(a.v,b.v)==0;
}
bool bn(bian a,bian b)
{
int ar=cj(a.v,b.v);
return ar>0||(ar==0&&cj(a.v,b.s-a.s)>0);
}
bool dn(dian x,bian y)
{
return cj(y.v,x-y.s)<=0;
}
bool cmp(const bian &x,const bian &y)
{
if(x.v.y==0&&y.v.y==0)
return x.v.x<y.v.x;
if((x.v.y<=0)==(y.v.y<=0))
return bn(x,y);
return x.v.y<y.v.y;
}
double dis2(bian a)
{
return sqrt(a.v.x*a.v.x+a.v.y*a.v.y);
}
bian yi(bian a,double r)
{
return bian(dian(a.s.x-a.v.y*r/dis2(a),a.s.y+a.v.x*r/dis2(a)),a.v);
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=1;i<=n;i++)
p[i].x=read(),p[i].y=read();
p[n+1]=p[1];
for(int i=1;i<=n;i++)
l[i]=bian(p[i],p[i+1]-p[i]);sort(l+1,l+1+n,cmp);
int top=0;
for(int i=1;i<=n;i++)
if(i==1||!px(l[i],l[i-1]))
l[++top]=l[i];
n=top;
int ll=1,rr=2;
s[1]=l[1],s[2]=l[2];
for(int i=3;i<=n;i++)
{
while(ll<rr&&dn(jd(s[rr],s[rr-1]),l[i]))
rr--;
while(ll<rr&&dn(jd(s[ll],s[ll+1]),l[i]))
ll++;
s[++rr]=l[i];
}
while(ll<rr&&dn(jd(s[rr],s[rr-1]),s[ll]))
rr--;
printf("%d\n",(rr-ll>1));
}
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! (半平面相交)

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

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

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

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

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

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

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

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

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

  7. POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)

    题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...

  8. 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)

    Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...

  9. POJ 3525 Most Distant Point from the Sea (半平面交+二分)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3476   ...

随机推荐

  1. python学习之-- IO多路复用 select模块

    python I/O多路复用包括3个模块,上一篇已经说过概念,这里我使用的是select模块实现一个ftp并发 服务器端核心代码: import socket,select import queue, ...

  2. foobar2000播放dff格式音乐的解决办法

    安装dff插件:http://www.foobar2000.org/components/view/foo_input_dsdiff 离线版本:链接:http://pan.baidu.com/s/1e ...

  3. flash update

    https://get.adobe.com/cn/flashplayer/otherversions/

  4. 中间件序列TDATASET为BUFFER演示代码

    procedure SendStream(const AStream: TStream);var Buffer: array[0..4095] of Byte; // 每包最大4K StartPos, ...

  5. poj 1258 Agri-Net(Prim)(基础)

    Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44487   Accepted: 18173 Descri ...

  6. protobuf 之 MessageLite 接口摘录

    class LIBPROTOBUF_EXPORT MessageLite { public: inline MessageLite() {} virtual ~MessageLite(); // Ba ...

  7. Web安全漏洞及攻击

    背景介绍 先说一个在互联网上常见,但是普通人又不太理解的东西--“验证码”. 验证码(CAPTCHA)是“Completely Automated Public Turing test to tell ...

  8. Scrum 常见错误实践 之 过长的站会

    站会看起来很简单,在实践过程中,却经常会出现控制不当而导致达不到应用效果的状况.我只是结合自己的一些过往经历作一些浅显的总结. 一个很常见的就是站会拖得太长. 一般来说站会不应该超过15分钟,每个人应 ...

  9. 到底该不该使用存储过程 MySQL查询性能优化一则

    到底该不该使用存储过程   看到<阿里巴巴java编码规范>有这样一条 关于这条规范,我说说我个人的看法 用不用存储过程要视所使用的数据库和业务场景而定的,不能因为阿里巴巴的技术牛逼,就视 ...

  10. 数据结构-二叉树的遍历(类C语言描写叙述)

    遍历概念     所谓遍历(Traversal)是指沿着某条搜索路线.依次对树中每一个结点均做一次且仅做一次訪问.訪问结点所做的操作依赖于详细的应用问题. 遍历是二叉树上最重要的运算之中的一个,是二叉 ...