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 (半平面交-求核)的更多相关文章

  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 3335 Rotating Scoreboard 半平面交求核

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

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

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

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

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

  6. poj 1474 Video Surveillance 【半平面交】

    半平面交求多边形的核,注意边是顺时针给出的 //卡精致死于是换(?)了一种求半平面交的方法-- #include<iostream> #include<cstdio> #inc ...

  7. ●poj 1474 Video Surveillance

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

  8. POJ 1279 Art Gallery 半平面交求多边形核

    第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...

  9. poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积

    /*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...

随机推荐

  1. Java 类名.class与类名.this 的区别?

    “类名.this”的语法在Java语言中叫做“qualified this”.相关规定在这里:Chapter 15. Expressions - Qualified this这个语法的主要用途是:在内 ...

  2. etymon word write alb pain high alt increase large agency ag lose weight fat assist out~3

        1● alb   2● write =====>rait     1● alg 2● pain   痛,疼痛           1● alt 2● high   高         1 ...

  3. 基本git指令

    --git包含命令行界面和图形化界面 1.Git安装之后需要进行一些基本信息设置 a.设置用户名:git  config -- global  user.name  '你再github上注册的用户名' ...

  4. VMware workstation 14 Pro下载、安装及激活码

    虚拟机安装 1.百度搜索VMware应用程序 2.功能介绍 3.下载完成 4.开始安装 双击应用程序开始安装 5.点击“下一步” 6.勾选“我接受” 选择“下一步” 7.安装文件的选择:1.默认安装路 ...

  5. Django 前台通过json 取出后台数据

    转载自:https://my.oschina.net/esdn/blog/814111 步骤1:后台数据通过 JSON 序列化成字符串 注意:1.json是1个字符串 2.通过json.dumps(' ...

  6. mysql 从库执行insert失败导致同步停止

    服务配置:一主一从,版本都是 5.5 .主库配置了 binlog-do-db binlog-ignore-db 问题复述:运营人员发现,昨天的数据统计不对.数据分析服务查询的是从库的数据. 到tomc ...

  7. Dell灵越 5559笔记本安装固态硬盘 BIOS设置

    固态硬盘的安装这里就不详细说明了,安装一共有两种 直接把原有的磁盘卸了,换成SSD(这种方法最简单) 另一种是把光驱卸掉,然后换上SSD(这里建议把原来的磁盘换到光驱里面,把SSD加到原来磁盘安装的位 ...

  8. [Leetcode 392]判断子序列 Is Subsequence

    [思路] 判断s是否为t的子串,所以length(s)<=length(t).于是两个指针,一次循环. 将s.t转换为数组p1.p2. i为过程中s的匹配长度. i=0空串,单独讨论返回true ...

  9. [leetcode整理]

    =======简单 leetcode164 Maximum Gap sort两次 =======有参考 330 Patching Array 98 Validate Binary Search Tre ...

  10. Unity3d代码及效率优化总结

    1.PC平台的话保持场景中显示的顶点数少于200K~3M,移动设备的话少于10W,一切取决于你的目标GPU与CPU. 2.如果你用U3D自带的SHADER,在表现不差的情况下选择Mobile或Unli ...