# Uvalive 4992 Jungle Outpost (semi-flat cross)

Source: Internet
Author: User

Test instructions: give you n a tower (dot) to form a clockwise convex hull, the enemy can destroy any tower, destroy the remaining tower and then make a convex bag

Select a point in the beginning of the main tower, to ensure that the enemy destroyed as many towers as possible when the main tower is still in the current convex hull, to find the most destroyed tower

Problem: The key is to choose the main tower in different places, the enemy will destroy different towers to let your main tower exposed

So think about it, find out all the different bumps that the enemy has formed after destroying the different towers, and finding out all the bumps.

Specifically, first enumerate the number of destroyed tower K, and then destroy any K tower formed by all the different convex hull for a turn, if the empty represents the destruction of K tower must be able to ensure that no matter where the main tower can be exposed (critical)

The intersection of all convex hull can be converted to find the straight line on all convex hull for half-plane intersection, followed by the attention of the enemy to destroy the continuous K-tower must be optimal, so the half-plane intersection of the line as long as N (understand)

Finally, we can find that the answer satisfies the monotony and can be answered by two points.

And then there's a little trick that is to find a straight line when you need to counter-clockwise (because half-plane intersection is counter-clockwise to ask)

`#include <Set>#include<map>#include<queue>#include<stack>#include<cmath>#include<vector>#include<string>#include<cstdio>#include<cstring>#include<iomanip>#include<stdlib.h>#include<iostream>#include<algorithm>using namespacestd;#defineEPS 1E-8/*Note that there may be output -0.000*/#defineSGN (x) (X<-eps -1:x<eps? 0:1)//X is a comparison of two floating-point numbers, note the return integer#defineCVS (x) (x > 0.0 x+eps:x-eps)//floating point Conversion#defineZero (x) (((x) >0? ( x):-(x)) <eps)//determine if it equals 0#defineMul (A, B) (a<<b)#defineDir (A, B) (a>>b)typedefLong Longll;typedef unsignedLong Longull;Const intinf=1<< -;Constll inf=1ll<< -;Const DoublePi=acos (-1.0);Const intmod=1e9+7;Const intmax=50010;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {}; intRead () {scanf ("%LF%LF",&x,&y); } Inline Pointoperator+(Constpoint& a)Const    {        returnPoint (x+a.x,y+a.y); } Inline Pointoperator*(DoubleAConst    {        returnPoint (x*a,y*a); } Inline Pointoperator-(Constpoint& a)Const    {        returnPoint (x-a.x,y-a.y); } InlineBOOL operator< (Constpoint& a)Const    {        returnSGN (x-a.x) <0|| Zero (x-a.x) &AMP;&AMP;SGN (Y-A.Y) <0; } InlineBOOL operator!=(Constpoint& a)Const    {        return! (zero (x-a.x) &&zero (ya.y)); }};typedef point Vector;structline{point P;    Vector v; DoubleAng//Polar AngleLine () {}; Line (Point P,vector v):p (P), V (v) {ang=atan2 (v.y,v.x); } InlineBOOL operator< (Constline& L)Const    {        returnang<L.ang; }};DoubleDis (Point a,point B) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));}DoubleCross (Vector a,vector 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;}intHarfplaneintersection (Line *l,intN) {Sort (l,l+n);//for (int i=0; i<n; ++i)//    {//printf ("%lf%lf%lf%lf\n", l[i].p.x,l[i].p.y,l[i].v.x,l[i].v.y);//    }    intFirst,last; Point*p=NewPoint[n]; Line*q=NewLine[n]; Q[first=last=0]=l;  for(intI=0; 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(Zero (Cross (q[last].v,q[last-1].v )) {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--;//printf ("%d\n", last-first-1);    returnMax (last-first-1,0);} Point Tow[max]; Line Convex[max];intSolve (intMidintN) {    if(n-mid<=2)//the remaining points        return 0;  for(intI=0; i<n; ++i) {//Note that the semi-flat is counterclockwiseConvex[i]=line (tow[i],tow[(i-mid-1+n)%n]-tow[i]);//key, the half-plane after the mid point is removed    }    returnharfplaneintersection (convex,n);}intDichotomy (intLefintRigintN//two points{     while(lef<rig) {        intMid= (lef+rig>>1);//The number of points deleted by the representative        if(Solve (Mid,n))//non-empty is the need to delete more points{lef=mid+1; }        Else{Rig=mid; }    }    returnlef;}intMain () {intN;  while(~SCANF ("%d",&N)) { for(intI=0; i<n; ++i) {tow[i].read (); } printf ("%d\n", Dichotomy (1, N,n)); }    return 0;}`

Uvalive 4992 Jungle Outpost (semi-flat cross)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.