●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 题目大意:给按照顺时针序的多边形顶点,问其是否有内核. —————————————————————————————— (和上道题目一模一样 ...
随机推荐
- bug终结者 团队作业第三周
bug终结者 团队作业第三周 团队展示 队名 bug终结者 队员风采: 杨京典 20162302 风格:先构建框架,在一 一实现,在实现的过程中不断测试和修改. 擅长的技术:拆分问题,使用相对简单的思 ...
- 201621123050 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...
- 团队作业7——第二次项目冲刺(Beta版本)
Deadline: 2017-12-10 23:00PM,以博客发表日期为准. 评分基准: 按时交 - 有分,检查的项目包括后文的三个方面 冲刺计划安排(单独1篇博客) 七天的敏捷冲刺(每两天发布 ...
- python 归并排序
def merge_sort(alist): if len(alist) <= 1: return alist # 二分分解 num = len(alist)/2 left = merge_so ...
- 推荐net开发cad入门阅读代码片段
转载自 Cad人生 的博客 链接:http://www.cnblogs.com/cadlife/articles/2668158.html 内容粘贴如下,小伙伴们可以看看哦. using Syst ...
- idea导入本地maven项目
首先把项目关闭File->Close Project 否则会将项目导入到当前项目中 回到主界面,点击Import Project 一定要选择项目的pom文件 默认设置,继续往下走 默认配置,下一 ...
- io文本加密
文本加密习题 package io; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Inpu ...
- Connect Appium Server Fail.A new session could not be created
1.由于安卓测试机性能低下,并不能支持测试工作,想安装一个模拟器帮助测试,然后发现群里有朋友发了一个夜神模拟器..下载..安装..美滋滋的准备运行脚本.What..居然报错了..orz..然后百度查找 ...
- Mybatis框架入门
Mybaits框架 一.什么是Mybatis MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了googl ...
- Spring Security入门(3-5)Spring Security 的鉴权 - 决策管理器和投票器
1.决策管理器的运行原理: 2.Spring Security提供的决策管理器实现 3.用户自定义的决策管理器