题目链接:http://poj.org/problem?id=1474
Time Limit: 1000MS Memory Limit: 10000K

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.

Problem solving report:

Description: 是否存在一个点把房间里面的各个地方都能看到。
Problem solving: 半平面交判核。

Accepted Code:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 105;
const double eps = 1e-7;
typedef struct point {
    double x, y;
}vect;
struct line {
    vect p;
    point u, v;
    bool operator < (const line& s) const {
        return atan2(s.p.y, s.p.x) > atan2(p.y, p.x);
    }
};
vect operator - (const point a, const point b) {
    return (vect){a.x - b.x, a.y - b.y};
}
double dist(const point a, const point b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int pnz(double x) {
    return x < -eps ? -1 : x > eps ? 1 : 0;
}
double Cross(const vect a, const vect b) {
    return a.x * b.y - a.y * b.x;
}
int Onleft(const point p, const line l) {
    return pnz(Cross(l.p, p - l.u));
}
point Inter(const line a, const line b) {
    double t = Cross(b.p, a.u - b.u) / Cross(a.p, b.p);
    return (point){a.u.x + t * a.p.x, a.u.y + t * a.p.y};
}
bool Halfplane(line Sline[], int n) {
    point Spt[MAXN];
    int Q[MAXN] = {0};
    int l = 0, r = 0;
    sort(Sline, Sline + n);
    for (int i = 1; i < n; i++) {
        while (l < r && Onleft(Spt[r - 1], Sline[i]) < 0)
            r--;
        while (l < r && Onleft(Spt[l], Sline[i]) < 0)
            l++;
        Q[++r] = i;
        if (!pnz(Cross(Sline[i].p, Sline[Q[r - 1]].p))) {
            r--;
            if (Onleft(Sline[i].u, Sline[Q[r]]) > 0)
                Q[r] = i;
        }
        else Spt[r - 1] = Inter(Sline[i], Sline[Q[r - 1]]);
    }
    while (l < r && Onleft(Spt[r - 1], Sline[Q[l]]) < 0)
        r--;
    while (l < r && Onleft(Spt[l], Sline[Q[r]]) < 0)
        l++;
    if (r - l < 2)
        return false;
    return true;
}
int main() {
    int n, kase = 0;
    point p[MAXN];
    line Sl[MAXN], Sline[MAXN];
    while (~scanf("%d", &n), n) {
        if (kase)
            printf("\n");
        for (int i = n - 1; i >= 0; i--)
            scanf("%lf%lf", &p[i].x, &p[i].y);
        p[n] = p[0];
        for (int i = 0; i < n; i++)
            Sl[i] = (line){p[i + 1] - p[i], p[i], p[i + 1]};
        printf("Floor #%d\n", ++kase);
        if (Halfplane(Sl, n))
            printf("Surveillance is possible.\n");
        else printf("Surveillance is impossible.\n");
    }
    return 0;
}