The bare half-plane intersection asks whether the polygon has a nucleus.
The core of the polygon: all vertices of the polygon can be seen on the polygon core, and the nucleus of the convex polygon is obviously the polygon itself.
The core of a polygon is a convex hull, and all sides of the polygon are made to the half plane of the polygon to determine whether the convex hull is formed.
Same subject and POJ3335.
Video surveillance
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 3438 |
|
Accepted: 1523 |
Description A friend of yours has taken the job's security officer at the Star-buy company, a famous depart-ment store. One of his tasks are 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 had only a limited budget, there'll be is only one camera in every floor. But these cameras could turn around to look in every direction.
The first problem is to choose where to install the camera for every floor. The only requirement are that every part of the the the the "must be visible from there. The following figure the left floor can is completely surveyed from the position indicated by a dot, while for the righ T floor, there are 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 are indeed a suitable position for them . He therefore asks you-to-write a program that, given a ground plan, de-termines whether there are a position from which th E whole floor is visible. All floor ground plans form rectangular polygons, whose edges does not intersect each of the other and touch are only at the Corners.
Input The input contains several floor descriptions. Every description starts with the number n of vertices this bound the floor (4 <= n <= 100). The next n lines contain the integers each, the x and y coordinates for the n vertices, given in clockwise order. All vertices is 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 "the floor" as shown in the sample output. Then print a line stating ' surveillance is possible. ' If there exists a position from which ' entire floor can be observ Ed, or print "surveillance is impossible." If there is no such position.
Print a blank line after each test case.Sample Input 40 00 11 11 080 00 21 21 12 12 23 23 00
Sample Output Floor #1Surveillance is possible. Floor #2Surveillance is impossible.
Source Southwestern European Regional Contest 1997 |
/* ***********************************************author:ckbosscreated time:2015 April 09 Thursday 19:43 00 seconds file Name :P oj1474.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace std; #define MP Make_pair#define PB Push_backconst Double eps = 1e-8;const double pi = ACOs ( -1.0); const double inf = 1e20;const int max p = 111;int dcmp (double D) {if (Fabs (d) <eps) return 0; return (d<0)? -1:1;} Inline double Sqr (double x) {return x*x;} struct point{double x,y;point (double _x=0,double _y=0): X (_x), Y (_y) {}void input () {scanf ("%lf%lf", &x,&y);} void output () {printf ("%.2lf%.2lf\n", x, y);} BOOL operator== (point a) const {return dcmp (a.x-x) ==0&&dcmp (a.y-y) ==0;} BOOL operator< (point a) const {return DCMP (A.x-x) ==0?dcmp (Y-A.Y) <0:x<a.x; }double Len () {return hypot (x, y);} Double Len2 () {return x*x+y*y;} Double distance (point P) {return hypot (X-P.X,Y-P.Y);} Point-Add (point P) {return-point (X+P.X,Y+P.Y);} Point Sub (point P) {return point (X-P.X,Y-P.Y);} Point Mul (double b) {return point (x*b,y*b);} Point Div (double b) {return point (x/b,y/b);} Double dot (point P) {return x*p.x+y*p.y;} Double det (point P) {return x*p.y-y*p.x;} Double rad (Point A,point b) {point P=*this;return fabs (atan2 (Fabs (A.sub (P)), Det (p)), B.sub (p). dot (A.sub (P))));}; struct Line{point a,b;line () {}line (point _a,point _b) {a=_a; b=_b;} BOOL operator== (const line v) const {return (A==V.A) && (B==V.B);} bool Parallel (line v) {return dcmp (B.sub (a). Det (V.b.sub (V.A))) ==0;} Point CrossPoint (line v) {double a1=v.b.sub (V.A). Det (A.sub (V.A));d ouble a2=v.b.sub (V.A). Det (B.sub (V.A)); ((A.X*A2-B.X*A1)/(A2-A1), (A.Y*A2-B.Y*A1)/(A2-A1));}; struct halfplane:public line{double Angle;halfplane () {}///a--≫b Lefthalfplane (Point _a,point _b) {a=_a; b=_b;} Halfplane (line v) {a=v.a; b=v.b;} void Calcangle () {angle=atan2 (b.y-a.y,b.x-a.x);} BOOL operator< (const Halfplane &b) const {return angle<b.angle;}}; struct Halfplanes{int n;halfplane Hp[maxp];p oint p[maxp];int que[maxp];int st,ed;void push (Halfplane tmp) {hp[n++]=tmp;} void unique () {int m=1,i;for (i=1;i<n;i++) {if (dcmp (hp[i].angle-hp[i-1].angle)) Hp[m++]=hp[i];else if (dcmp (hp[m-1) . B.sub (HP[M-1].A). Det (hp[i].a.sub (hp[m-1].a)) >0)) hp[m-1]=hp[i];} N=m;} BOOL Halfplaneinsert () {int i;for (int i=0;i<n;i++) hp[i].calcangle (); sort (hp,hp+n); unique (); que[st=0]=0; que[ed=1 ]=1;p[1]=hp[0].crosspoint (hp[1]); for (i=2;i<n;i++) {while (st<ed&&dcmp (Hp[i].b.sub (hp[i].a). Det (p[ Ed].sub (HP[I].A))) <0) Ed--;while (st<ed&&dcmp (Hp[i].b.sub (hp[i].a). Det (p[st+1].sub (HP[I].A)))) <0) st++;que[++ed]=i;if (Hp[i].parallel (hp[que[ed-1])) return False;p[ed]=hp[i].crosspoint (Hp[que[ed-1]]);} while (ST<ED&&DCMP (hp[st).B.sub (HP[QUE[ST]].A). Det (p[ed].sub (hp[que[st]].a))) <0) Ed--;while (st<ed&&dcmp (hp[que[ed]].b.sub (HP[QUE[ED]].A). Det (p[st+1].sub (hp[que[ed]].a))) <0) st++;if (st+1>=ed) return False;return true;}}; int N;int Main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); int Cas=1;while (scanf ("%d", &n) &&n) {vector<point> vp;for (int i=0 ; i<n;i++) {point tp; Tp.input (); VP.PB (TP);} Halfplanes HFS; hfs.n=0;for (int i=0;i<n;i++) {////P[i] <---p[i+1]hfs.push (halfplane (vp[(i+1)%n],vp[i]));} printf ("Floor #%d\n", cas++); bool Isok=hfs.halfplaneinsert (); if (isok==true) puts ("surveillance is possible."); Else puts ("surveillance is impossible."); Putchar (10);} return 0;}
POJ 1474 Video surveillance semi-planar intersection to find out if the polygon has a core