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. URL to load resources from the classpath in Java

    In Java, you can load all kinds of resources using the same API but with different URL protocols: fi ...

  2. 使用Swagger2构建强大的RESTful API文档(1)(二十二)

    由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这 ...

  3. css 让div 的高度和屏幕的高度一样

    <html><head><title>无标题文档</title><style type="text/css">html, ...

  4. elasticsearch在CentOS环境下开机启动

    验证环境,OS版本:CentOS-7-x86_64-Minimal-1708:ES版本:elasticsearch-6.2.2. 1.创建文件elasticsearch #!/bin/bash # # ...

  5. 蓝桥杯—ALGO-2 最小最大公倍数

    问题描述已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少. 输入格式输入一个正整数N. 输出格式输出一个整数,表示你找到的最小公倍数.样例输入9样例输出504数据规模与约定1 ...

  6. day10-高阶函数

    高阶函数 高阶函数:就是把函数当成参数传递的一种函数,例如: def add(x,y,f): return f(x)+f(y) print(add(-8,11,abs)) 结果: 19 解释: 调用a ...

  7. django 中下载文件与下载保存为excel

    一.django 中下载文件 在实际的项目中很多时候需要用到下载功能,如导excel.pdf或者文件下载,当然你可以使用web服务自己搭建可以用于下载的资源服务器,如nginx,这里我们主要介绍dja ...

  8. Win10访问不到XP共享的解决:

    不知道别人的是怎么解决. 反正我这么解决了. 我的win10笔记本,是使用windows帐户登陆的.可以同步很多东西. 同事的电脑是台式老古董XP. 扫描不到网上邻居,手动\\ip也访问不到. 最后安 ...

  9. Java:下拉列表绑定后台数据

    后台传进来一个List集合,存着某对象集合,将其显示在下拉列表 一.HTML代码 页面有个下拉列表,如图所示: <td style="width:30%"> <s ...

  10. 五. Python基础(5)--语法

    五. Python基础(5)--语法 1 ● break结束的是它所在的循环体, continue是让它所在的循环体继续循环 # 打印: 1 10 2 10 3 10 4 10 5 10 6 10 7 ...