1038: [ZJOI2008] Lookout tower

Source: Internet
Author: User

Half-plane intersection.

The half plane refers to the left side of a straight line (and I don't know if it's right)

Semi-planar intersection refers to a lot of half-plane public parts.

The solution of this problem must be in the half-plane intersection of each line.

And the Watchtower may only be at the inflection point of the dots or the half-plane intersection.

Find out half-plane intersection, enumeration can be.

#include <cstdio>#include<algorithm>#include<cstring>#include<cmath>#defineEPS 1e-7using namespacestd;Const intMAXN = -+Ten;structPoint {Doublex, y; }p[maxn],t;structLine {Doublek,b; voidInit (Point p1,point p2) {k= (P1.Y-P2.Y)/(p1.x-p2.x); b=p2.y-k*p2.x; }}L[MAXN],S[MAXN];intn,sp;Doubleres=1e11;BOOLcmp (line X,line y) {if(ABS (X.K-Y.K) <eps)returnx.b<y.b; returnx.k<Y.K;}    Point Inter (line L1,line L2) {Point res; Res.x= (l2.b-l1.b)/(l1.k-L2.K); Res.y=l1.k*res.x+l1.b; returnRes;}voidpush (line l) { while(sp>=2&& Inter (s[sp],l). x < Inter (s[sp-1],S[SP]). x) sp--; s[++sp]=l;}DoubleFDoublex) {Doubleres=0;  for(intI=1; i<=sp;i++) Res=max (res,s[i].k*x+s[i].b); returnRes;}DoubleGDoublex) {inti;  for(i=n;i&&x<p[i].x;i--); returnp[i].y+ (x-p[i].x)/(p[i+1].x-p[i].x) * (p[i+1].y-p[i].y); }intMain () {scanf ("%d",&N);  for(intI=1; i<=n;i++) scanf ("%LF",&p[i].x);  for(intI=1; i<=n;i++) scanf ("%LF",&p[i].y);  for(intI=1; i<n;i++) L[i].init (p[i],p[i+1]); Sort (L+1, L +n,cmp);  for(intI=1; i<n;i++)if(i==n-1|| ABS (l[i].k-l[i+1].K) >EPS) push (L[i]);  for(intI=1; i<=n;i++) Res=min (Res,f (p[i].x)-p[i].y);  for(intI=1; i<sp;i++) {T=inter (s[i],s[i+1]); Res=min (res,t.y-g (t.x)); } printf ("%.3lf\n", RES); return 0;}

1038: [ZJOI2008] Lookout tower

Contact Us

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.