POJ - 1474 :Video Surveillance (半平面交-求核)
pro:顺时针给定多边形,问是否可以放一个监控,可以监控到所有地方,即问是否存在多边形的核。 此题如果两点在同一边界上(且没有被隔段),也可以相互看到。
sol:求多边形是否有核。先给直线按角度排序,然后增量法即可,复杂度O(NlogN)。
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
const double eps=1e-;
struct point{
double x,y;
point(){}
point(double xx,double yy):x(xx),y(yy){}
};
struct line{
point a;//起点
point p;//起点到终点的向量
double angle;
};
double dot(point a,point b){ return a.x*b.x+a.y*b.y;}
double det(point a,point b){ return a.x*b.y-a.y*b.x;}
point operator *(point A,double p){ return point(A.x*p,A.y*p);}
point operator +(point A,point B){return point(A.x+B.x,A.y+B.y);}
point operator -(point A,point B){return point(A.x-B.x,A.y-B.y);}
double getangle(point a){ return atan2(a.y,a.x);}
double getangle(line a){ return getangle(a.p);}
point llintersect(line A,line B)
{
point C=A.a-B.a;
double t=det(C,B.p)/det(B.p,A.p);
return A.a+A.p*t;
}
point s[maxn]; line t[maxn],q[maxn]; int head,tail;
bool cmp(line a,line b){
double A=getangle(a),B=getangle(b);
point t=(b.a+b.p)-a.a;
if(fabs(A-B)<eps) return det(a.p,t)>=0.0;
return A<B;
}
bool onright(line P,line a,line b)
{
point o=llintersect(a,b);
point Q=o-P.a;
return det(Q,P.p)>; //如果同一直线上不能相互看到,则>=0
}
bool halfplaneintersect(int N)
{
s[N+]=s[];
rep(i,,N) t[i].a=s[i],t[i].p=s[i+]-s[i];
sort(t+,t+N+,cmp);
int tot=;
rep(i,,N-) {
if(fabs(getangle(t[i])-getangle(t[i+]))>eps)
t[++tot]=t[i];
}
t[++tot]=t[N]; head=tail=;
rep(i,,tot){
while(tail>head+&&onright(t[i],q[tail],q[tail-])) tail--;
while(tail>head+&&onright(t[i],q[head+],q[head+])) head++;
q[++tail]=t[i];
}
while(tail>head+&&onright(t[head+],q[tail],q[tail-])) tail--;return tail-head>;
}
void solve(int C,int N)
{
for(int i=N;i>=;i--) scanf("%lf%lf",&s[i].x,&s[i].y);
printf("Floor #%d\n",C);
if(halfplaneintersect(N)) puts("Surveillance is possible.\n");
else puts("Surveillance is impossible.\n");
}
int main()
{
int N,C=;
while(~scanf("%d",&N)&&N) solve(++C,N);
return ;
}
POJ - 1474 :Video Surveillance (半平面交-求核)的更多相关文章
- POJ 1474 Video Surveillance 半平面交/多边形核是否存在
http://poj.org/problem?id=1474 解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上... /********************* ...
- POJ 1474 Video Surveillance(半平面交)
题目链接 2Y,模版抄错了一点. #include <cstdio> #include <cstring> #include <string> #include & ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- poj 1474 Video Surveillance - 求多边形有没有核
/* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...
- poj 1474 Video Surveillance (半平面交)
链接:http://poj.org/problem?id=1474 Video Surveillance Time Limit: 1000MS Memory Limit: 10000K Total ...
- poj 1474 Video Surveillance 【半平面交】
半平面交求多边形的核,注意边是顺时针给出的 //卡精致死于是换(?)了一种求半平面交的方法-- #include<iostream> #include<cstdio> #inc ...
- ●poj 1474 Video Surveillance
题链: http://poj.org/problem?id=1474 题解: 计算几何,半平面交 半平面交裸题,快要恶心死我啦... (了无数次之后,一怒之下把onleft改为onright,然后还加 ...
- POJ 1279 Art Gallery 半平面交求多边形核
第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...
- poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
/*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...
随机推荐
- Mockito:一个强大的用于Java开发的模拟测试框架
https://blog.csdn.net/zhoudaxia/article/details/33056093 介绍 本文将介绍模拟测试框架Mockito的一些基础概念, 介绍该框架的优点,讲解应用 ...
- vs 编译库文件
vs编译的库文件 静态库 debug和release版本 需要分开编译,我编译和实践的结果. 但是我也发现有的debug release都用同一个(搞不清楚). 然后添加到工程应用. 静态库 附件 ...
- read later
https://groups.google.com/forum/#!msg/pylearn-users/FYtpaQKoC4c/ubitO_JUC1kJ 网上论坛 发布回复 ...
- ES6中的Promise.resolve()的作用
var foo = { then: (resolve, reject) => resolve('foo') }; var resolved = Promise.resolve(foo); 相当于 ...
- 熔断监控面板(Hystrix Dashboard)
Hystrix Dashboard Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Comma ...
- Jdbc连接数据库基本步骤
Jdbc连接数据库的基本步骤: package demo.jdbc; import java.sql.Connection; import java.sql.DriverManager; import ...
- springmvc添加拦截器
springmvc.xml配置如下: 除了 sysFile 下的所有接口,以及user下的loginUser接口,其他的所有接口都会经过拦截器UserInterceptor处理 <mvc:int ...
- spin lock自旋锁 双链表操作(多线程安全)(Ring0)
通过spin lock自旋锁 ,为每个链表都定义并初始化一个锁,在需要向该链表插入或移除节点时不使用前面介绍的普通函数,而是使用如下方法: ExInterlockedInsertHeadList(&a ...
- MATLAB中mexFunction函数的接口规范(转)
reference:https://www.cnblogs.com/haoyul/p/5606720.html https://www.cnblogs.com/zeakey/p/3984733.htm ...
- 网口扫盲二:Mac与Phy组成原理的简单分析(转)
1. general 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成.DMA控制器通常属于CPU的一部分,用虚线放在这里是为了表示DMA控制器可能会参与到网口数据传输中. 对于上述的三部分 ...