题链:

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. Java作业-数据库

    本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结与数据库相关内容. 在Java中使用数据库要经过以下几个步骤: 1. 注册 JDBC 驱动 Class.forName("com ...

  2. 项目Alpha冲刺Day12

    一.会议照片 二.项目进展 1.今日安排 修复全局的日期转换问题,完成用户所有相关的模块,对全局的异常处理做优化.其他模块进行一部分实现. 2.问题困难 全局异常处理后发现没有进行按照链进行下去,造成 ...

  3. mysql基础篇 - 其他基本操作

    基础篇 - 其他基本操作         其他基本操作 一.实验简介 本节实验中我们将学习并实践数据库的其他基本操作:索引.视图,导入和导出,备份和恢复等. 这些概念对于数据库管理员而言都非常重要,请 ...

  4. Linux之用户与用户组

    1.Linux是一种 多用户多任务分时操作系统. 2.Linux的用户只有两个等级:root用户和非root用户.   Linux系统默认 内置了root用户 和一些非root用户,如nobody,a ...

  5. OpenGL中怎么把世界坐标系变成屏幕坐标系

    对这个3D坐标手动进行OpenGL的四个变换,得到的结果就是屏幕上的像素坐标.前三个变换(Model, View, Projection)都是4x4矩阵,操作对象是四维向量,所以需要把(100, 10 ...

  6. jquery 表双击某行时,取出某行中各列的数值.

      <script> $(function () { $("tr").dblclick(function () { var txt = $("table tr ...

  7. 学习phalcon框架按照官网手册搭建第一个项目注册功能

    中文手册官网:http://phalcon.ipanta.com/1.3/tutorial.html#bootstrap 官网提供http://www.tutorial.com项目源码github地址 ...

  8. AngularJS1.X学习笔记8-自定义指令(上)

    AngulaJS的指令是一种非常强大的特性,一个ng-repeat就能让我们非常方便的展示一个数据列表,指令相当于是一个组件,为我们将一些东西封装起来了,提供了复用的可能性.个人认为自定义指令还是比较 ...

  9. Python内置函数(38)——zip

    英文文档: zip(*iterables) Make an iterator that aggregates elements from each of the iterables. Returns ...

  10. C语言学习之弹跳小球

    重新回过头来看了一遍C语言,才发现我自己的无知,C语言其实好强大,我之前学的不过是一点C语法和做几个数学题.正好3月份的考试要考C语言,重新学一遍,先是在中国大学mooc上把翁恺老师的C语言刷了一遍, ...