您的位置:首页 > 运维架构

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 #1
Surveillance 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: