bsoj 1850 【POJ1474】监控摄像头
2016-02-20 14:55
281 查看
Input
输入文件有多组数据。每一组的第一行是一个整数n(4<=n<=100),表示房间的示意图是一个n边形。接下来n行,按照顺时针给出这n个点的坐标。最后一组的第一行是0,表示结束。
Output
如果能找出安放摄像机的点则输出Floor #1
Surveillance is possible.
否则输出:
Floor #1
Surveillance is impossible.
#后边的数字表示房间编号,按输入数据由小到大编号,第一个房间编号为1。每一组数据完后输出一个空行。
Sample Input
40 00 11 11 080 00 21 21 12 12 23 23 00
Sample Output
Floor #1Surveillance is possible.
Floor #2
Surveillance is impossible.
这个题不知道为什么,在windows上FC和输出文件一模一样,在Linux测评机上就是过不去。
也是半平面交,只不过有一点变化。
如果是凸多边形就一定可行,不管用它。
主要是凹多边形。
用自己的边去做半平面,割自己的面积,割完后只要还有点(而不是面积)就可以。
我用的是一个超大的矩形作平面,这样据说要快一点。
如图,割出来后就不行了。
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; struct Point { double x,y; }P[100005],last,cur,first; int n,m,T; double Cross(Point a,Point b,Point c){ return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y); } Point Get_NewPoint(Point a,Point b,Point l,Point r){ Point Temp; double x=abs(Cross(a,l,r)); double y=abs(Cross(b,l,r)); Temp.x=(a.x*y+b.x*x)/(x+y); Temp.y=(a.y*y+b.y*x)/(x+y); return Temp; } void Cut(Point x,Point y){ Point Temp[50]; int top=0; P[n+1]=P[1]; double l=Cross(P[1],y,x); for(int i=2;i<=n+1;i++){ double r=Cross(P[i],y,x); if(l>=0){ Temp[++top]=P[i-1]; if(r<0)Temp[++top]=Get_NewPoint(P[i-1],P[i],x,y); } else if(r>0)Temp[++top]=Get_NewPoint(P[i-1],P[i],x,y); l=r; } for(int i=1;i<=top;i++)P[i]=Temp[i]; n=top; } void Get_Ans(){ P[n+1]=P[1]; double Ans=0.0; for(int i=2;i<=n+1;i++){ Ans+=(P[i-1].x-P[i].x)*(P[i-1].y+P[i].y)/2.0; } printf("%.3lf",abs(Ans)); } int main(){ T=0; while(scanf("%d",&m)==1&&m){ T++; n=4; P[1].x=-1e8,P[1].y-1e8; P[2].x=-1e8,P[2].y=1e8; P[3].x=1e8,P[3].y=1e8; P[4].x=1e8,P[4].y=-1e8; scanf("%lf%lf",&first.x,&first.y); last=first; for(int i=2;i<=m;i++){ scanf("%lf%lf",&cur.x,&cur.y); Cut(last,cur); last=cur; } Cut(last,first); printf("Floor #%d\n",T); if(n)printf("Surveillance is possible.\n\n"); else printf("Surveillance is impossible.\n\n") ; } return 0; }
相关文章推荐
- linux下安装googletest
- linux下VFS
- linux samba安装及配置
- 开发环境配置(三) 局域网中其他机器不能访问本机IIS网站
- 我使用过的Linux桌面发行版
- CentOS 7 (RHEL 7)服务管理命令的变化
- svn“Previous operation has not finished; run 'cleanup' if it was interrupted“报错的解决方法
- linux上安装pip笔记
- 在了解hadoop过程中碰到的一些问题
- Linux-QT 开发环境搭建以及编译镜像
- ubuntu关机和重启命令
- Linux进程间通信——使用共享内存
- Linux gcc使用
- 搭建局域网CentOS Yum服务器
- 软键盘遮挡住popupWindow问题
- 设计系统的组织,其产生的设计和架构等价于组织间的沟通结构(转)
- 查看nginx apache mysql php原始编译
- CentOS7 安装mysql
- 用shell脚本执行mysql语句
- linux字符驱动之中断按键