题链:

http://poj.org/problem?id=1474

题解:

计算几何,半平面交

半平面交裸题,快要恶心死我啦。。。

(了无数次之后,一怒之下把onleft改为onright,然后还加了一个去重,总算是过了。。。)

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 1550
using namespace std;
const double eps=1e-8;
int sign(double x){
if(fabs(x)<=eps) return 0;
return x<0?-1:1;
}
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
void Read(){scanf("%lf%lf",&x,&y);}
}D[MAXN];
typedef Point Vector;
struct Line{
Point s; Vector v; double ang;
Line(){}
Line(Point _s,Vector _v):s(_s),v(_v){ang=atan2(v.y,v.x);}
friend bool operator < (Line A,Line B){return sign(A.ang-B.ang)<0;}
}L[MAXN];
bool operator == (Point A,Point B){return sign(A.x-B.x)==0&&sign(A.y-B.y)==0;}
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double k){return Vector(A.x*k,A.y*k);}
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double operator * (Vector A,Vector B){return A.x*B.x+A.y*B.y;}
bool OnRight(Point P,Line A){return sign(A.v^(P-A.s))<0;}
Point LLI(Line A,Line B){//Line_Line_Intersection
Vector u=B.s-A.s;
double t1=(u^B.v)/(A.v^B.v);
return A.s+A.v*t1;
}
int HPI(int lnt){//Half_Plane_Intersection
static Point QP[MAXN]; static Line QL[MAXN];
sort(L+1,L+lnt+1);
int l=1,r=1,dnt=0; QL[r]=L[1];
for(int i=2;i<=lnt;i++){
while(l<r&&OnRight(QP[r-1],L[i])) r--;
while(l<r&&OnRight(QP[l],L[i])) l++;
QL[++r]=L[i];
if(sign(QL[r-1].v*QL[r].v)>0&&sign(QL[r-1].v^QL[r].v)==0){
r--; if(!OnRight(L[i].s,QL[r])) QL[r]=L[i];
}
if(l<r) QP[r-1]=LLI(QL[r-1],QL[r]);
}
while(l<r&&OnRight(QP[r-1],QL[l])) r--;
if(r-l<=1) return 0;
QP[r]=LLI(QL[r],QL[l]);
for(int i=l;i<=r;i++) D[++dnt]=QP[i];
dnt=unique(D+1,D+dnt+1)-D-1;
return dnt-(dnt>1&&D[dnt]==D[1]);
}
int main(){
int n,Case=0;
while(~scanf("%d",&n)&&n){
for(int i=1;i<=n;i++)
D[i].Read(),L[i]=Line(D[i],D[i-1]-D[i]);
L[1]=Line(D[1],D[n]-D[1]);
n=HPI(n);
printf("Floor #%d\n",++Case);
//printf("%d\n",n);
if(n>0) printf("Surveillance is possible.\n");
else printf("Surveillance is impossible.\n");
printf("\n");
}
return 0;
}

●poj 1474 Video Surveillance的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. POJ1474:Video Surveillance(求多边形的核)(占位)

    A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- me ...

  7. Video Surveillance - POJ 1474(判断是否存在内核)

    题目大意:询问是否在家里装一个监视器就可以监控所有的角落. 分析:赤裸裸的判断多边形内核题目. 代码如下: #include<iostream> #include<string.h& ...

  8. POJ - 1474 :Video Surveillance (半平面交-求核)

    pro:顺时针给定多边形,问是否可以放一个监控,可以监控到所有地方,即问是否存在多边形的核. 此题如果两点在同一边界上(且没有被隔段),也可以相互看到. sol:求多边形是否有核.先给直线按角度排序, ...

  9. POJ1474:Video Surveillance——题解

    http://poj.org/problem?id=1474 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— (和上道题目一模一样 ...

随机推荐

  1. Welcome to StackEdit!

    Welcome to StackEdit! Hey!our first Markdown document in StackEdit1. Don't delete me, I'm very helpf ...

  2. c语言一,二数组

    一.PTA实验作业 题目1:7-4 简化的插入排序 1. 本题PTA提交列表 2. 设计思路 1.定义整形变量N,temp,i. 2.输入N 3.通过for(i=1;i<=N;i++)的循环语句 ...

  3. iOS开发点滴-添加阴影效果

    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:_backView.bounds]; _backView.layer.masks ...

  4. AWS EMR上搭建HBase环境

    0. 概述 AWS的EMR服务为客户提供的托管 Hadoop 框架可以让您轻松.快 速.经济高效地在多个动态可扩展的 Amazon EC2 实例之间分发和处理 大量数据.您还可以运行其他常用的分发框架 ...

  5. js判断flash文件是否加载完毕

    轮询判断加载进度 img的加载完成有onload方法,一直不知道该怎么判断swf文件是否加载完毕了? 在应用中使用了轮询判断加载进度值PercentLoaded是否达到100,经测试,可以达到效果. ...

  6. JAVA_SE基础——13.选择结构语句

    if选择结构 语法: if(条件){ 代码块 } public class Test{ public static void main(String[] args){ int a = 5; if(a ...

  7. windows7.0旗舰版安装后控制面板自带的Microsoft程序

    1.不要卸载,否则会出现安装其他软件时缺少动态链接库

  8. Linux实战案例(3)创建和删除用户

    建用户: adduser phpq                            //新建phpq用户passwd phpq                            //给php ...

  9. Spring Security 入门(3-10)Spring Security 的四种使用方式

    原文链接: http://www.360doc.com/content/14/0724/17/18637323_396779659.shtml 下面是作者的一个问题处理

  10. DevExpress控件的GridControl实现行多选

    最近用到DevExpress控件的GridControl控件,需要用到行多选的操作,在网上找的资料,自己总结一下. 先展示一下效果: