博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1474 Video Surveillance
阅读量:4353 次
发布时间:2019-06-07

本文共 2592 字,大约阅读时间需要 8 分钟。

只需要判断就行了 不需要正宗的半平面交

 

/*Point operator & (Line A,Line B){    Point C=A.s;    double t=((A.s-B.s)^(B.s-B.e))/((A.s-A.e)^(B.s-B.e));    C.x+=(A.e.x-A.s.x)*t; C.y+=(A.e.y-A.s.y)*t;    return C;}半平面交 1.首先规定逆时针给点 判断的时候直接求有向面积 面积为负则是顺时针给的点 2.极角排序 (可以去重 留下靠左的一个)3.模拟双端队列 判断队列尾部两线的交点和头部两线的交点在新加入线段哪一侧     左侧即合法 直接加入 右侧即不合法 删掉堆尾4.因为我们 3 过程中始终保持队列数量至少为2 所以最后判断头部和尾部的合法性    剩下的边<=2条的话 说明不存在内核NOTE: 此题特殊 之存在上下左右方向的线  最后决定的线也只有4条 可以直接判断 不用打半平面交    所以&交点也不需要考虑两线平行的情况*/#include
#include
#include
using namespace std;const int N=150;const double eps=1e-9;struct Point{ double x,y;Point(){} Point(double _x,double _y){x=_x,y=_y;}}p[N];struct Line{ Point s,e;Line(){} Line(Point _s,Point _e){s=_s,e=_e;} }l[N],q[N];int n,T;Point operator - (Point A,Point B) {
return Point(A.x-B.x,A.y-B.y);} double operator ^ (Point A,Point B) {
return A.x*B.y-A.y*B.x;} Point operator & (Line A,Line B){ Point C=A.s; double t=((A.s-B.s)^(B.s-B.e))/((A.s-A.e)^(B.s-B.e)); C.x+=(A.e.x-A.s.x)*t; C.y+=(A.e.y-A.s.y)*t; return C;}bool Isf() // 判断给出的点是否是逆时针的{ double res=0; for(int i=2;i
eps;}bool check(Line a,Line b,Line c) // 判断 a,b的交点是否在c的左侧包括线上{ Point d=a&b; return ((d-c.s)^(c.e-c.s))
0) return 1; else if(A.x<0&&A.y==0) return 2; else if(A.x==0&&A.y<0) return 3; else return 4;}bool cmp(Line a,Line b){ int f1=from(a),f2=from(b); if(f1!=f2) return f1
(%.2lf,%.2lf)\n",l[1].s.x,l[1].s.y,l[1].e.x,l[1].e.y);//printf(" left : (%.2lf,%.2lf) -> (%.2lf,%.2lf)\n",l[2].s.x,l[2].s.y,l[2].e.x,l[2].e.y);//printf(" down : (%.2lf,%.2lf) -> (%.2lf,%.2lf)\n",l[3].s.x,l[3].s.y,l[3].e.x,l[3].e.y);//printf(" right : (%.2lf,%.2lf) -> (%.2lf,%.2lf)\n",l[4].s.x,l[4].s.y,l[4].e.x,l[4].e.y);//printf(" up : (%.2lf,%.2lf)\n",up.x,up.y);//printf(" left : (%.2lf,%.2lf)\n",left.x,left.y);//printf(" down : (%.2lf,%.2lf)\n",down.x,down.y);//printf(" right : (%.2lf,%.2lf)\n",right.x,right.y); if(up.s.x-down.s.x<-eps)return 0; if(left.s.y-right.s.y<-eps) return 0; return 1;}int main(){ while(scanf("%d",&n)&&n) { T++; for(int i=1;i<=n;i++) { double x,y; scanf("%lf%lf",&x,&y); p[i]=Point(x,y); } if(!Isf()) for(int i=1;i<=(n>>1);i++) swap(p[i],p[n-i+1]); p[n+1]=p[1]; for(int i=1;i<=n;i++) l[i]=Line(p[i],p[i+1]); printf("Floor #%d\n",T); if(solve()) puts("Surveillance is possible."); else puts("Surveillance is impossible."); putchar('\n'); } return 0;}/*bian81 01 10 10 31 31 22 22 0dian81 10 10 21 21 12 12 01 0*/

 

转载于:https://www.cnblogs.com/lxy8584099/p/10421746.html

你可能感兴趣的文章
树的数据结构
查看>>
MyEclipse导入Color Theme
查看>>
Vue开发微信H5 微信分享签名失败问题解决方案
查看>>
Linux - 配置SSH免密通信 - “ssh-keygen”的基本用法
查看>>
Python(2.7.6) glob - 匹配指定模式的文件
查看>>
HTTP - 持久连接
查看>>
添加路由时啥时候是dev啥时候是gw
查看>>
redis 中文字符显示
查看>>
登录日志分析常用查询
查看>>
Codeforces Round #228 (Div. 1) 388B Fox and Minimal path
查看>>
【nosql实现企业网站系列之一】mongodb的安装
查看>>
短信服务供应商价格总览
查看>>
获取本机IP(考虑多块网卡、虚拟机等复杂情况)
查看>>
笔记之_java整理ORM框架
查看>>
CentOS下安装python3.x版本
查看>>
CAP定理(原则)以及BASE理论
查看>>
「玩转树莓派」搭建属于自己的云盘服务
查看>>
有道语料库爬虫
查看>>
VS2019 实用设置
查看>>
for循环语句之求和,阶乘,求偶,求n次篮球蹦起高度
查看>>