Input
Output
Floor #1
Surveillance is possible.
否則輸出:
Floor #1
Surveillance is impossible.
#後邊的數字表示房間編號,按輸入數據由小到大編號,第一個房間編號爲1。每一組數據完後輸出一個空行。
Sample Input
Sample Output
#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;
}