看着网上说这个要注意那个要注意。。什么m<=2不行要=0才行。。看着莫名其妙。
默默地写完感觉那些注意事项然并卵。
仍然是判断多边形是否存在。半平面交出来点数超过2就存在。
神TM忘打空行。又一个PE。。
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 1005;
struct Point {
double x, y;
Point(){}
Point(double _x, double _y) : x(_x), y(_y) {}
Point operator +(const Point &b) const { return Point(x + b.x, y + b.y); }
Point operator -(const Point &b) const { return Point(x - b.x, y - b.y); }
double operator *(const Point &b) const { return x * b.y - y * b.x; }
Point operator *(double b) const { return Point(b * x, b * y); }
} poly[N];
struct Line {
Point x, v;
double ang;
Line(){}
Line(const Point &_x, const Point &_v) : x(_x), v(_v), ang(atan2(_v.y, _v.x)) { }
bool operator <(const Line &b) const {
if (ang == b.ang) return v * (b.x - x) < 0;
return ang < b.ang;
}
bool operator ==(const Line &b) const { return ang == b.ang; }
Point intersection(const Line &b) {
Point u = x - b.x;
double t = (b.v * u) / (v * b.v);
return x + v * t;
}
} lines[N];
bool right(const Point &p, const Line &l) {
return l.v * (p - l.x) < 0;
}
int half_plane_intersection(Line l[], int n, Point *poly) {
static Line q[N];
sort(l + 1, l + n + 1);
n = unique(l + 1, l + n + 1) - (l + 1);
int f = 1, r = 0, m = 0;
q[++r] = l[1]; q[++r] = l[2];
for (int i = 3; i <= n; i++) {
while (f < r && right(q[r].intersection(q[r - 1]), l[i])) r--;
while (f < r && right(q[f].intersection(q[f + 1]), l[i])) f++;
q[++r] = l[i];
}
while (f < r && right(q[r].intersection(q[r - 1]), q[f])) r--;
while (f < r && right(q[f].intersection(q[f + 1]), q[r])) f++;
q[r + 1] = q[f];
for (int i = f; i <= r; i++)
poly[++m] = q[i].intersection(q[i + 1]);
return m;
}
int main() {
int t = 0, n, i, j, line_num;
while (1) {
line_num = 0;
scanf("%d", &n);
if (n == 0) break;
for (j = 1; j <= n; j++)
scanf("%lf %lf", &poly[j].x, &poly[j].y);
poly[n + 1] = poly[1];
for (j = 1; j <= n; j++)
lines[++line_num] = Line(poly[j], poly[j] - poly[j + 1]);
int m = half_plane_intersection(lines, line_num, poly);
printf("Floor #%d\nSurveillance is %spossible.\n\n", ++t, m > 2 ? "" : "im");
}
return 0;
}
Video Surveillance
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3626 | Accepted: 1622 |
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.
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.
![](https://i-blog.csdnimg.cn/blog_migrate/1905a10656bd399d3cb27da230ae91d4.jpeg)
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.
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.
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.
Source