半平面交求多边形的核,注意边是顺时针给出的

//卡精致死于是换(?)了一种求半平面交的方法……
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=505;
int n,cas;
const double eps=1e-8;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a) const
{
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);
}
}a[N],p[N];
struct bian
{
dian s,v;//s表示向量的起点,v表示向量的方向和长度(从(0,0)射出)
double a;
bian(dian S=dian(),dian V=dian())
{
s=S,v=V;
a=atan2(v.y,v.x);
}
}l[N],s[N];
int sgn(double x)
{
return x<-eps?-1:x>eps;
}
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.0;
}
dian jd(bian x,bian y)//求交点
{
return x.s+x.v*(cj(x.s-y.s,y.v)/cj(y.v,x.v));
}
dian nor(dian a)
{
return dian(-a.y,a.x);
}
bool px(bian x,bian y)//判断平行
{
return sgn(cj(y.v,x.v))==0;
}
bool bn(bian x,bian y)//x在y的逆时针方向(平行先左后右
{
double ar=cj(x.v,y.v);
return (sgn(ar)>0)||((sgn(ar)==0)&&sgn(cj(x.v,y.s-x.s))>0);
}
bool dn(dian x,bian y)//点在线的逆时针方向
{
return sgn(cj(y.v,x-y.s))>0;
}
bool cmp(const bian &x,const bian &y)//极角排序
{
// if(sgn(x.v.y)==0&&sgn(y.v.y)==0)//同与x轴平行
// return x.v.x<y.v.x;
// if((sgn(x.v.y)<=0)==(sgn(y.v.y)<=0))//同在x轴上或下(包括x轴)
// return bn(x,y);
// return x.v.y<y.v.y;//一上一下下在前
return sgn(x.a-y.a)==-1;
}
dian ite(bian a,bian b)
{
return a.s+a.v*(cj(b.v,a.s-b.s)/cj(a.v,b.v));
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=0;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
p[n]=p[0];
for(int i=0;i<n;i++)
l[i]=bian(p[i]-nor(p[i]-p[i+1])*eps,p[i]-p[i+1]);
sort(l,l+n,cmp);
int ll=0,rr=0;
s[rr++]=l[0];
for(int i=1;i<n;i++)//每次新加入向量,就会删掉在向量右边的交点(线上的也要删),维护的凸包首尾都是要删除的,最后还要模拟插入队头,把队尾中多余的半平面去掉
{
while(ll+1<rr&&!dn(p[rr-2],l[i]))
rr--;
while(ll+1<rr&&!dn(p[ll],l[i]))
ll++;
s[rr++]=l[i];
if(ll+1<rr&&sgn(cj(s[rr-1].v,s[rr-2].v))==0)
{
rr--;
if(dn(l[i].s,s[rr-1]))
s[rr-1]=l[i];
}
if(ll+1<rr)
p[rr-2]=ite(s[rr-1],s[rr-2]);
}
while(ll+1<rr&&!dn(p[rr-2],s[ll]))
rr--;//cout<<rr<<endl;
if(rr-ll>1)
printf("Floor #%d\nSurveillance is possible.\n",++cas);
else
printf("Floor #%d\nSurveillance is impossible.\n",++cas);
printf("\n");
}
return 0;
}

poj 1474 Video Surveillance 【半平面交】的更多相关文章

  1. POJ 1474 Video Surveillance 半平面交/多边形核是否存在

    http://poj.org/problem?id=1474 解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上... /********************* ...

  2. POJ 1474 Video Surveillance(半平面交)

    题目链接 2Y,模版抄错了一点. #include <cstdio> #include <cstring> #include <string> #include & ...

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

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

  4. poj 1474 Video Surveillance (半平面交)

    链接:http://poj.org/problem?id=1474 Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total ...

  5. ●poj 1474 Video Surveillance

    题链: http://poj.org/problem?id=1474 题解: 计算几何,半平面交 半平面交裸题,快要恶心死我啦... (了无数次之后,一怒之下把onleft改为onright,然后还加 ...

  6. POJ1474 Video Surveillance(半平面交)

    求多边形核的存在性,过了这题但是过不了另一题的,不知道是模板的问题还是什么,但是这个模板还是可以过绝大部分的题的... #pragma warning(disable:4996) #include & ...

  7. poj1474Video Surveillance(半平面交)

    链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...

  8. 2018.07.03 POJ 1279Art Gallery(半平面交)

    Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...

  9. POJ 3335 Rotating Scoreboard 半平面交求核

    LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...

随机推荐

  1. UVAlive 3026 KMP 最小循环节

    KMP算法: 一:next数组:next[i]就是前面长度为i的字符串前缀和后缀相等的最大长度,也即索引为i的字符失配时的前缀函数. 二:KMP模板 /* pku3461(Oulipo), hdu17 ...

  2. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1054

    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1054 这个错误困扰了我一个下午  插入数据总是错误 ...

  3. Jmeter的几个关键配置文件

    1.配置文件位于bin目录下: 2.配置文件可能存在优先级关系,好像user.properties会覆盖jmeter.properties,一般修改配置都是修改或者添加user.properties, ...

  4. 【Nginx】I/O多路转接之select、poll、epoll

    当需要读两个以上的I/O的时候,如果使用阻塞式的I/O,那么可能长时间的阻塞在一个描述符上面,另外的描述符虽然有数据但是不能读出来,这样实时性不能满足要求,大概的解决方案有以下几种: 1.使用多进程或 ...

  5. ExpandableListView的使用以及信息的高亮显示

    ExpandableListView是ListView控件的延伸,它能够对数据进行分组显示和隐藏,并统计总数量.可进行滚动,对某一内容高亮显示. <1>编写xml布局文件,用于获取Expa ...

  6. HTML的DIV如何实现垂直居中

    外部的DIV必须有如下代码 display:table-cell; vertical-align:middle;   这样可以保证里面的东西,无论是DIV还是文本都可以垂直居中

  7. 【转】LoadRunner监控 -- Linux的17个指标

    这17个指标根据需要设置,指标设置的越多,对服务器真实值影响越大,所以要秉承按需而设的原则.   1.Average load:Average number of processes simultan ...

  8. C# LINQ Unity 单例

    C# LINQ   1. 自定义 Master,Kongfu 类 1 class Master 2 { 3 4 public int Id { get; set; } 5 public string ...

  9. HTML5开发实战——Sencha Touch篇(1)

    学习了很多主要的Sencha Touch内容,已经了解了Sencha Touch的开发模式.接下来一段时间我们将利用Sencha Touch来进行自己的web应用构建. 先要解决的是前端的问题.从最简 ...

  10. 关于Address already in use: connect问题分析及解决方案

    最近给一个公司做项目的时候,在完成上报的功能 的时候,发现数据量稍微大的时候,会出现这样的问题: 错误描述: com.microsoft.sqlserver.jdbc.SQLServerExcepti ...