2300: [HAOI2011] Defense Construction Description Recently the contradiction between A and B countries intensified, in order to prevent accidents, a country to build a long line of defense, of course, the construction of the line of defense, Be sure to fix the city in need of protection inside the perimeter. But the upper class A is still undecided, which cities should be used as the object of protection? Again, owing to the limited funding of country A, So I hope you can help to accomplish one of the following tasks: 1. Give all of your city coordinates 2.A to the top of the discussion, taking into account the economic problems, decided to cancel the protection of I city, that is, I city does not need to be in the perimeter of the 3.A of the top of the country to ask for protection of the remaining cities, the total amount For. Note that the 1-length line of defense costs 1. A country's topography is such, shape, x axis is a river, the equivalent of a natural line of defense, do not need you to build a country there are always two cities in the river, a point is (0,0), a point is (n,0), all the other points of the horizontal axis are greater than 0 less than N, the ordinate is greater than 0. A state-owned one is not in the capital (0,0) and (n,0). (0,0), (n,0) and the capital of these three cities must be protected.
, the a,b,c,d,e point is a city, and currently have to protect, then the building of the line of defense will be a-b-c-d, the cost is the length of the line segment AB + line BC length + segment CD length, if, this time to revoke the protection of point B, then the line of defense becomes
The first line of input, three integer n,x,y, respectively, indicates that the riverside city and Capital is (0,0), (n,0), (x, y). The second line, an integer m. The next m line, two integers per line, a, a, a, is the coordinate of a non-capital city of Country A (a, b). The next integer, Q, indicates the total number of modifications and queries. Then the Q line is either shaped like 1 I, or shaped like 2, which respectively represents the revocation of protection and questioning of the city of the first I. Output
1 lines per query, a real number V, represents the cost of building a line of defense, leaving two decimal places
Sample Input4 2 1
2
1 2
3 2
5
2
1 1
2
1 2
2Sample Output6.47
5.84
4.47hintm<=100000,q<=200000,n>1
The coordinates of all points are within 10000 and the data is guaranteed With focus source
Analysis
It was a very small thought at first.
This is a dynamic convex package. Can be taken offline, the deletion point becomes the insertion point.
The problem has a special, There are always two cities in the river, a point is (0,0), a point is (n,0), the rest of all points of the horizontal axis is greater than 0 is less than N, the ordinate is greater than 0.
That is, the lower convex hull is the longest line in the bottom, as long as one upper convex package is maintained.
(indicates that the dynamic convex package is not yet true)
This problem is only set maintenance, you know the point of insertion of the first two points of influence (Lower_bound)
The judgment is that x is the first keyword and y is the second keyword.
And then expand the deletion point is good.
So hard to beat Orz,,, unexpectedly 1 A.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <cmath>7#include <Set>8 using namespacestd;9 #defineMAXN 100010Ten One structP A { - intx, y; - }A[MAXN]; the intLen; - - intm; - +Poperator-(P x,p y) - { + P tt; Att.x=x.x-y.x; attt.y=x.y-y.y; - returntt; - } - - BOOL operator< (P x,p y) {return(x.x==y.x)? (X.Y<Y.Y):(x.x<y.x);} - in intDot (P x,p y) {returnx.x*y.x+x.y*y.y;} - intCross (P x,p y) {returnx.x*y.y-x.y*y.x;} to + Set<P>T; - Doubleans; the * voidins (P NW) $ {Panax Notoginseng Set<p>:: iterator R=t.lower_bound (NW), l=R,tt; -l--; the if(Cross (NW-*L,*R-*L) >=0)return; +Ans-=sqrt ((Double) Dot (*r-*l,*r-*l)); A while(1) the { +tt=r,r++; - if(R==t.end ()) Break; $ if(Cross (NW-*TT,NW-*R) <=0) Break; $Ans-=sqrt ((Double) Dot (*r-*tt,*r-*tt)); - t.erase (TT); - } the while(l!=T.begin ()) - {Wuyitt=l,l--; the if(Cross (*L-*TT,*L-NW) <=0) Break; -Ans-=sqrt ((Double) Dot (*l-*tt,*l-*tt)); Wu t.erase (TT); - } About T.insert (NW); $Tt=t.find (NW); l=r=tt; -l--;r++; -Ans+=sqrt ((Double) Dot (nw-*l,nw-*l)) +sqrt ((Double) Dot (nw-*r,nw-*R)); - } A + BOOLMARK[MAXN]; the intqr[2*Maxn],al; - Double as[MAXN]; $ voidInit () the { the intN; thescanf"%d",&n); thea[0].x=0, a[0].y=0; T.insert (a[0]); -a[0].x=n,a[0].y=0; T.insert (a[0]); inans=0; thescanf"%d%d", &a[0].x,&a[0].y); theans+=N; AboutINS (a[0]); thescanf"%d",&m); the for(intI=1; i<=m;i++) the { +scanf"%d%d",&a[i].x,&a[i].y); - } the Bayimemset (Mark,0,sizeof(Mark)); the intQ; thescanf"%d",&q); - for(intI=1; i<=q;i++) - { the intx, y; thescanf"%d",&x); the if(x==1) the { -scanf"%d",&y); theqr[i]=y; themark[y]=1; the }94 Else the { theqr[i]=-1; the }98 } About for(intI=1; i<=m;i++)if(!Mark[i]) ins (a[i]); -Al=0;101 for(inti=q;i>=1; i--)102 {103 if(qr[i]==-1)104 { the as[++al]=ans;106 }107 Else108 {109 ins (A[qr[i]]); the }111 } the for(inti=al;i>=1; i--) printf ("%.2lf\n", as[i]);113 } the the intMain () the {117 init ();118 return 0;119}
View Code
2016-12-17 10:07:03
"Bzoj 2300" 2300: [HAOI2011] perimeter construction (dynamic convex hull +set)