Jungle Outpost
Time limit:15.000 seconds
Description
There is a military base lost deep in the jungle. It is surrounded by n watchtowers with ultrasonic generators. In this problem watchtowers is represented by points on a plane.
watchtowers Generate ultrasonic field and protect all objects that is strictly inside the towers ' convex hull. There is no tower strictly inside the convex hull and no three towers be on a straight line.
The enemy can blow up some towers. If this happens, the protected area was reduced to a convex hull of the remaining towers.
The base commander wants to build headquarters inside the protected area. In order to increase IT security, he wants to maximize the number of towers, the enemy needs to blow the H Eadquarters unprotected.
Input
The input file contains several test cases, each of the them as described below.
The first line of all one of the cases contains a single integer n(3n50000)-The number of WA Tchtowers. The next n lines of the input file contain the Cartesian coordinates of watchtowers, one pair of coordinates Per line. Coordinates is integer and does not exceed106 by absolute value. Towers is listed in the order of traversal of their convex hull in clockwise direction.
Output
For each test case, write to the output file the number of watchtowers the enemy have to blow up to compromise headquarters Protection if the headquarters is placed optimally.
Sample Input
3 0 0 50 50 60 10 5 0 0 0 10 10 20 20 10 25 0
Sample Output
12
The two-point answer is whether the semi-planar intersection exists. Note: It is better to destroy several points in succession than to destroy them separately.
The establishment of a half-plane is represented by a straight line. Then the left side of the line represents an area, so be aware of the vector direction of the line.
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<queue>#include<map>#include<Set>#include<stack>#include<algorithm>using namespacestd;#defineX First#defineY Second#defineRoot 1,n,1#defineLR rt<<1#defineRR rt<<1|1#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1typedefLong LongLl;typedef pair<int,int>PII;Const intN =50050 ;Const intINF = 1e9+7;Const DoubleEPS = 1e-8;intN; inlineintDCMP (Doublex) { if(Fabs (x) <eps)return 0; returnx<0?-1:1;}structPoint {Doublex, y; Point () {}; Point (DoubleXDoubley): x (x), Y (y) {}; BOOL operator< (ConstPoint &a)Const { returnDCMP (x-a.x) <0|| (dcmp (x-a.x) = =0&& dcmp (Y-A.Y) <0 ); }}e[n];typedef point Vector;structLine {point P; Vector v; //directional vector Doubleang; Line () {}; Line (point P, Vector v):p (P), V (v) {ang=atan2 (v.y,v.x);} BOOL operator< (ConstLine &l)Const { returnAng <L.ang; }}; Pointoperator-(Point A, point B) {returnPoint (a.x-b.x,a.y-b.y); }pointoperator+ (Point A, point B) {returnPoint (a.x+b.x,a.y+b.y); }pointoperator* (Point A,DoubleP) {returnPoint (a.x*p,a.y*p); }inlineDoubleCross (Point A, point B) {returna.x*b.y-a.y*b.x;}BOOLOnleft (Line L, point P) {returnCross (L.V, P-L.P) >0 ;} Point Getintersection (Line A, line B) {Vector u= A.P-B.P; Doublet = Cross (B.V,U)/Cross (A.V,B.V); returnA.P + a.v*t;}BOOLHPI (line* L,intN) {sort (L, l+N); intFirst, last;//Deque,Point *p =NewPoint[n];//P[i] is q[i] and q[i+1] "s intersection PointLine *q =NewLine[n]; Q[first=last=0] = l[0]; for(inti =1; I < n; ++i) { while(First < last &&!) Onleft (L[i], p[last-1])) last--; while(First < last &&!) Onleft (L[i], P[first])) first++; q[++last] =L[i]; if(Fabs (Cross (q[last].v,q[last-1].V)) <EPS) { Last--; if(Onleft (Q[last], L[I].P)) q[last] =L[i]; } if(First < last) p[last-1] = Getintersection (q[last-1],q[last]); } while(First < last &&!) Onleft (q[first],p[last-1])) last--; //Delete useless plane if(Last-first <=1)return false ; return true ;} Line L[n];BOOLOkintnum) { inttot =0 ; for(inti =0; I < n; ++i) {L[tot+ +] = line (e[(i+num+1)%n],e[i]-e[(i+num+1)%n]);//convex in clockwise direction } if( ! HPI (L,tot))return true ; return false ;}voidRun () { for(inti =0; I < n; ++i) {scanf ("%LF%LF",&e[i].x,&e[i].y); } if(n = =3) {puts ("1");return ; } intAns =0, L =0, R = N-3 ; while(L <=r) {intMid = (l+r) >>1; if(OK (mid)) ans= Mid, R = mid-1 ; ElseL= Mid +1 ; } printf ("%d\n", ans);}intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin); #endif //LOCAL while(SCANF ("%d", &n)! =EOF) Run ();}
View Code
Uvalive 4992 Jungle Outpost (semi-planar deposit)