●poj 1474 Video Surveillance
题链:
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的更多相关文章
- poj 1474 Video Surveillance - 求多边形有没有核
/* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...
- poj 1474 Video Surveillance (半平面交)
链接:http://poj.org/problem?id=1474 Video Surveillance Time Limit: 1000MS Memory Limit: 10000K Total ...
- POJ 1474 Video Surveillance 半平面交/多边形核是否存在
http://poj.org/problem?id=1474 解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上... /********************* ...
- POJ 1474 Video Surveillance(半平面交)
题目链接 2Y,模版抄错了一点. #include <cstdio> #include <cstring> #include <string> #include & ...
- poj 1474 Video Surveillance 【半平面交】
半平面交求多边形的核,注意边是顺时针给出的 //卡精致死于是换(?)了一种求半平面交的方法-- #include<iostream> #include<cstdio> #inc ...
- POJ1474:Video Surveillance(求多边形的核)(占位)
A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- me ...
- Video Surveillance - POJ 1474(判断是否存在内核)
题目大意:询问是否在家里装一个监视器就可以监控所有的角落. 分析:赤裸裸的判断多边形内核题目. 代码如下: #include<iostream> #include<string.h& ...
- POJ - 1474 :Video Surveillance (半平面交-求核)
pro:顺时针给定多边形,问是否可以放一个监控,可以监控到所有地方,即问是否存在多边形的核. 此题如果两点在同一边界上(且没有被隔段),也可以相互看到. sol:求多边形是否有核.先给直线按角度排序, ...
- POJ1474:Video Surveillance——题解
http://poj.org/problem?id=1474 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— (和上道题目一模一样 ...
随机推荐
- Beta冲刺NO.5
Beta冲刺 第五天 1. 昨天的困难 1.昨天的困难主要是在类的整理上,一些逻辑理不清,也有一些类写的太绝对了,扩展性就不那么好了,所以,昨天的困难就是在重构上. 页面结构太凌乱,之前没有统筹好具体 ...
- 关于python中的operator.itemgetter()函数的用法
1. operator.itemgetter(num)函数 表示对对象的第num维数据进行操作获取. >>>import operator >>>a = [1, 2 ...
- node框架express
见识到原生nodeJs服务器的恶心后,我们来用下简单好用的框架吧~ 服务器无非主要提供接口和静态文件读取,直接上代码: const express = require('express'); cons ...
- github入门:设置添加ssh key<转>
GitHub是个分布式的版本控制库.github通过git使用,可以方便的记录代码版本. 通过github可以学习优秀的代码,可以改进提交其他项目中的bug,借助社区力量促进软件优化完善. 国内外大量 ...
- GIT入门笔记(6)- 向版本库添加文本文件
1.把文本文件添加到版本库? 所有的版本控制系统,其实只能跟踪文本文件的改动,比如TXT文件,网页,所有的程序代码等等,Git也不例外. 版本控制系统可以告诉你每次的改动,比如在第5行加了一个单词&q ...
- Linux实战案例(4)CentOS清除用户登录记录和命令历史方法
CentOS清除用户登录记录和命令历史方法 清除登陆系统成功的记录[root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信 ...
- c#**************
ddfbvbb c v我wossssssss
- Zookeeper分布式服务协调组件
1.简介 Zookeeper是一个分布式服务协调组件,是Hadoop.Hbase.Kafka的重要组件,它是一个为分布式应用提供一致性服务的组件. Zookeeper的目标就是封装好复杂易出错的服 ...
- LinkedHashMap就这么简单【源码剖析】
前言 声明,本文用得是jdk1.8 前面已经讲了Collection的总览和剖析List集合以及散列表.Map集合.红黑树还有HashMap基础了: Collection总览 List集合就这么简单[ ...
- python/零起点(一、字符串)
python/零起点(一.字符串) 字符串(str) 字符串是可迭代的 str()强制转成字符串类型 字符串是有序的,且不可变的数据类型. 字符串转换整型的案例: 1 name=['guobaoyua ...