Calculating geometry/half-plane intersection
Said to be semi-planar, in fact, only to maintain a lower convex shell just ... Visible lines with 1007 Horizontal
For each line segment, you can see that the point of this segment is in the "Top" of this segment, then the intersection of all n-1 line segments for a visual area is to ask for a half plane intersection ... (Good pull)
At first I was thinking: directly find the bottom of the lower convex hull, its Y value is the answer spicy ~ But obviously not >_> this question is to ask is the tower's lowest height ... Not only to consider the tower, but also to see the bottom of the AH!
So how do we find it? We can see that with the change of X, the height of the tower (that is, the vertical distance from the ground to the convex hull, the difference of the y-coordinate) is a piecewise function, and the segmented point is the vertex of the ground and the convex hull! And in each paragraph, the value of the tower height is a function once! After a bold conjecture, the Small (BU) Heart (Yong) proves that we find that the extremum of a piecewise function is taken at the point of segmentation and at the boundary point.
So that is the answer to these points to calculate ... The points are O (n) ...
1 /**************************************************************2 problem:10383 User:tunix4 language:c++5 result:accepted6 time:0 Ms7 memory:1292 KB8 ****************************************************************/9 Ten //Bzoj 1038 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; atInlineintGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } in Const intn=310, inf=~0u>>2; -typedefLong LongLL; totypedefDoubleLF; + ConstLF eps=1e-8; - /******************tamplate*********************/ the structpoint{ * lf x, y; $ voidRead () {scanf ("%LF%LF",&x,&y);}Panax Notoginseng }p[n]; - structline{DoubleK,b;} L[n],st[n]; the Line Make_line (point A,point b) { + Line tmp; Atmp.k= (A.Y-B.Y)/(a.x-b.x); thetmp.b=a.y-tmp.k*a.x; + returntmp; - } $ intN,top; $InlineBOOLCMP (line A,line b) { - if(Fabs (A.K-B.K) <eps)returna.b<b.b; - returna.k<B.K; the } - Doublecrossx (line X1,line x2) {Wuyi return(x2.b-x1.b)/(x1.k-x2.k); the } - voidInsert (Line a) { Wu while(top) { - if(Fabs (ST[TOP].K-A.K) <eps) top--; About Else if(top>1&& CROSSX (a,st[top-1]) <= $CROSSX (st[top],st[top-1])) top--; - Else Break; - } -st[++top]=A; A } + lf up (lf x) { theLF ans=0.0; -F (I,1, top) $Ans=max (ans,st[i].k*x+st[i].b); the returnans; the } the lf down (lf x) { the intPos; - for(pos=1;p os<n && p[pos+1].x<x;pos++); in if(pos==n)return-1e10; theLine Tmp=make_line (p[pos],p[pos+1]); the returntmp.k*x+tmp.b; About } the the intMain () { the #ifndef Online_judge +Freopen ("1038.in","R", stdin); -Freopen ("1038.out","W", stdout); the #endifBayin=getint (); theF (I,1, N) scanf ("%LF",&p[i].x); theF (I,1, N) scanf ("%LF",&p[i].y); -F (I,1, N-1) L[i]=make_line (p[i+1],p[i]); -Sort (L +1, L +n,cmp); theF (I,1, N-1) Insert (L[i]); theLF ans=1e10; theF (I,1, N) ans=min (Ans,up (p[i].x)-p[i].y); theF (I,2, top) { - Point p; theP.X=CROSSX (st[i-1],st[i]); thep.y=st[i].k*p.x+st[i].b; theAns=min (ans,p.y-Down (p.x));94 } theprintf"%.3lf\n", ans); the return 0; the}
View Code
1038: [ZJOI2008] Watchtower time limit:10 Sec Memory limit:162 MB
submit:1043 solved:470
[Submit] [Status] [Discuss] Description
Committed to the construction of a national model of the village of village village Dadzhi H, decided to establish a lookout tower in the village, in order to strengthen the village law and order. We abstract the H village into a one-dimensional contour. As shown we can use the top contour polyline of a mountain (x1, y1), (x2, y2), .... (Xn, yn) to describe the shape of H village, here X1 < X2 < ...< xn. The Watchtower can be built anywhere between [X1, xn], but must meet any location from the top of the Watchtower to see H village. It can be seen that building watchtower at different locations requires different heights. To save money, the Dadzhi mayor wants to build a tower as small as possible. Please write a program to help Dadzhi village head to calculate the minimum height of the tower.
Input
The first line contains an integer n, which represents the number of nodes in the contour polyline. Next the first row n integers, for x1 ~ xn. The third line, n integers, is y1 ~ yn.
Output
Contains only one real number, which is the minimum height of the tower and is exactly three digits after the decimal point.
Sample Input"Input Sample One"
6
1 2 4 5 6 7
1 2 2 4 2 1
"Input Sample Two"
4
10 20 49 59
0 Ten 0Sample Output"Output Example One"
1.000
"Output Example II"
14.500HINT
For 100% of data, n≤300, the absolute value of input coordinates is not more than 106, pay attention to the problem caused by real error.
Source [Submit] [Status] [Discuss]
"Bzoj" "1038" "ZJOI2008" Lookout tower