POJ1474-Video Surveillance

Video Surveillance
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3190 Accepted: 1408

Description

A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- ment store. One of his tasks is to install a video surveillance system to guarantee the security of the customers (and the security of the merchandise of course) on all of the store's countless floors. As the company has only a limited budget, there will be only one camera on every floor. But these cameras may turn around to look in every direction.

The first problem is to choose where to install the camera for every floor. The only requirement is that every part of the room must be visible from there. In the following figure the left floor can be completely surveyed from the position indicated by a dot, while for the right floor, there is no such position, the given position failing to see the lower left part of the floor.

Before trying to install the cameras, your friend first wants to know whether there is indeed a suitable position for them. He therefore asks you to write a program that, given a ground plan, de- termines whether there is a position from which the whole floor is visible. All floor ground plans form rectangular polygons, whose edges do not intersect each other and touch each other only at the corners.

Input

The input contains several floor descriptions. Every description starts with the number n of vertices that bound the floor (4 <= n <= 100). The next n lines contain two integers each, the x and y coordinates for the n vertices, given in clockwise order. All vertices will be distinct and at corners of the polygon. Thus the edges alternate between horizontal and vertical.

A zero value for n indicates the end of the input.

Output

For every test case first output a line with the number of the floor, as shown in the sample output. Then print a line stating "Surveillance is possible." if there exists a position from which the entire floor can be observed, or print "Surveillance is impossible." if there is no such position.

Print a blank line after each test case.

Sample Input

4
0 0
0 1
1 1
1 0
8
0 0
0 2
1 2
1 1
2 1
2 2
3 2
3 0
0

Sample Output

Floor #1
Surveillance is possible.

Floor #2
Surveillance is impossible.
//AC代码
/*
参考博客:http://blog.csdn.net/accry/article/details/6070621
此博客对半平面方面知识讲得很全面,通俗

题意:就是一个在一个房子里面放一个摄像头
能将所有的地方监视到的放摄像头的地点的集合即为多边形的核
经常会遇到让你判定一个多边形是否有核的问题

此题利用半平面交求多边形的核
多边形的核:
它是平面简单多边形的核是该多边形内部的一个点集
该点集中任意一点与多边形边界上一点的连线都处于这个多边形内部。
*/
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
const double eps=1e-8;
const double PI=acos(-1.0);
const double e=2.7182818284590452354;
const int INF=0x7fffffff;
const int Max=1001;
#define zero(x) (((x)>0?(x):-(x))<eps)
#define mm(a,b) memset(a,b,sizeof(a))
using namespace std;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
typedef struct Node
{
    double x;
    double y;
}point;
point list[Max],stack[Max];
point pp[Max],qq[Max],pnt[Max];
int n;
int top;

int cnt;
int curcnt;
double xmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double Distance(point p1,point p2)// 返回两点之间欧氏距离
{
	return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
bool cmp(point p1,point p2)
{
    double temp;
    temp=xmult(list[0],p1,p2);
    if(temp>0)
        return true;
    if(temp==0&&(Distance(list[0],p1)<Distance(list[0],p2)))
        return true;
    return false;
}
void convex_hull()//凸包模板
{
    int i;
    for(i=1;i<n;i++)
    {
        point temp;
        if((list[i].y<list[0].y)||(list[i].y==list[0].y&&list[i].x<list[0].x))
            swap(list[0],list[i]);
    }
    sort(list+1,list+n,cmp);
    top=1;
    stack[0]=list[0];
    stack[1]=list[1];
    for(i=2;i<n;i++)
    {
        while(top>=1&&xmult(stack[top-1],stack[top],list[i])<=0)
            top--;
        top++;
        stack[top]=list[i];
    }
}
void Init(int n)//初始化
{
    int i;
    for(i=1;i<=n;i++)
    {
        pp[i]=pnt[i];
    }
    pp[n+1]=pp[1];//n个点有n条边
    pp[0]=pp[n];//用于计算相交的点(第n个点在直线左侧并且第一个点在右侧)
    cnt=n;//多边形顶点数
}
void GetLine(point u,point v,double &a,double &b,double &c)//两点确定一条直线
{
    a=v.y-u.y;
    b=u.x-v.x;
    c=v.x*u.y-u.x*v.y;
}
point Intersect(point u,point v,double a,double b,double c)//求直线切割交于多边形边上的一点
{
    double q=fabs(a*u.x+b*u.y+c);
    double p=fabs(a*v.x+b*v.y+c);
    point res;
    res.x=(p*u.x+q*v.x)/(q+p);
    res.y=(p*u.y+q*v.y)/(q+p);
    return res;
}
void CutLine(double a,double b,double c)//直线切割模板
{
    int i;
    curcnt=0;
    for(i=1;i<=cnt;i++)
    {
        if(a*pp[i].x+b*pp[i].y+c>=0)//当前顶点在直线的右侧(或者直线上)
        {
            qq[++curcnt]=pp[i];
        }
        else
        {
            if(a*pp[i-1].x+b*pp[i-1].y+c>0)//前一个顶点在直线的右侧
            {
                qq[++curcnt]=Intersect(pp[i],pp[i-1],a,b,c);
            }
            if(a*pp[i+1].x+b*pp[i+1].y+c>0)//同样的,后一个顶点在直线的右侧
            {
                qq[++curcnt]=Intersect(pp[i],pp[i+1],a,b,c);
            }
        }
    }
    for(i=1;i<=curcnt;i++)//更新切割后的多边形
    {
        pp[i]=qq[i];
    }
    pp[curcnt+1]=pp[1];
    pp[0]=pp[curcnt];
    cnt=curcnt;
}
int main()
{
    int m,i,j;
    double a,b,c,num;
    num=1;
    while(cin>>n&&n)
    {
        for(i=1;i<=n;i++)
        {
            cin>>pnt[i].x>>pnt[i].y;
        }
        pnt[n+1]=pnt[1];
        Init(n);
        //顺时针方向为切割后多边形
        for(i=1;i<=n;i++)
        {
            GetLine(pnt[i],pnt[i+1],a,b,c);
            CutLine(a,b,c);
        }
        cout<<"Floor #"<<num++<<endl;
        if(cnt==0)
            cout<<"Surveillance is impossible."<<endl;
        else
            cout<<"Surveillance is possible."<<endl;
        cout<<endl;//坑爹的没注意题目PE了一次
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值