题链:

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. hashlib 加密

    import hashlib def md5(args): hash = hashlib.md5(bytes('aaadf',encoding='utf-8')) hash.update(bytes( ...

  2. 2017 清北济南考前刷题Day 4 afternoon

    期望得分:30+50+30=110 实际得分:40+0+0=40 并查集合并再次写炸... 模拟更相减损术的过程 更相减损术,差一定比被减数小,当被减数=减数时,停止 对于同一个减数来说,会被减 第1 ...

  3. javascript实现小鸟飞行轨迹

    javascript实现小鸟飞行轨迹 代码如下:

  4. ubuntu启动报/root/.profile mesg:ttyname failed错误的解决办法

    修改/root/.profile文件,如下命令 sudo gedit /root/profile 将文中的最后一行mesg n修改成tty -s && mesg n

  5. linux作为服务器,利用top命令查看服务进程的耗用情况

    top命令查看进程服务如下: 其中shift+m可以按照内存的消耗进行排序,shift+p是按照cpu的消耗进程,排序,其中对cpu的消耗是一定时间,谁占用的时间越长消耗越大, 还有按空格键,会刷新一 ...

  6. 使用JavaScript实现一个俄罗斯方块

    清明假期期间,闲的无聊,就做了一个小游戏玩玩,目前游戏逻辑上暂未发现bug,只不过样子稍微丑了一些-.-项目地址:https://github.com/Jiasm/tetris在线Demo:http: ...

  7. Linux知识积累(1)awk的使用方法

    参见:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html 简介 awk是一个强大的文本分析工具,相对于grep的查找,se ...

  8. 新概念英语(1-43)Hurry up!

    新概念英语(1-43)Hurry up! How do you know Sam doesn't make the tea very often? A:Can you make the tea, Sa ...

  9. leetcode算法: Find Largest Value in Each Tree Row

    '''You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 ...

  10. SSM登陆注册

    package com.coingod.controller; import java.io.IOException;import java.io.PrintWriter;import java.ut ...