Bzoj 1038 ZJOI2008 Lookout tower half-plane intersection

Source: Internet
Author: User

Topic and simulated annealing: see http://blog.csdn.net/popoqqq/article/details/39340759

This time with half a plane to write it again ... After the semi-planar intersection is obtained. Enumerate each point of the original and half-plane intersection, and find out the answer can be

#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < Algorithm> #define M 310#define eps 1e-7using namespace std;struct point{double x, y;} Points[m];struct line{point *p1,*p2;double k,b;void get_parameters () {k= (double) (p1->y-p2->y)/(p1->x-p2- &GT;X); b=p1->y-k*p1->x;} BOOL operator < (const line &x) const{if (Fabs (K-X.K) <eps) return B < X.b;return K < X.K;}} Lines[m];int n;double ans=1e11;line *stack[m];int top;inline point get_intersection (const line &l1,const line & L2) {point re;re.x=-(l1.b-l2.b)/(L1.K-L2.K); Re.y=l1.k*re.x+l1.b;return re;} void Insert (line &l) {while (top>=2) {if (Get_intersection (*stack[top],l). x < Get_intersection (*stack[top-1] , *stack[top]). x)--top;elsebreak;} Stack[++top]=&l;} Double F (double x) {int i;double re=0;for (i=1;i<=top;i++) Re=max (re,stack[i]->k*x+stack[i]->b); return re;} Double G (double x) {int i;for (i=n;i;i--) if (x>=points[i].x) Break;return points[i].y+ (x-points[i].x)/(points[i+1].x-points[i].x) * (POINTS[I+1].Y-POINTS[I].Y);} int main () {int i;cin>>n;for (i=1;i<=n;i++) scanf ("%lf", &points[i].x), for (i=1;i<=n;i++) scanf ("%lf", &AMP;POINTS[I].Y); for (i=1;i<n;i++) lines[i].p1=points+i,lines[i].p2=points+i+1,lines[i]. Get_parameters (); sort (lines+1,lines+n); for (i=1;i<n;i++) if (i==n-1| | Fabs (LINES[I].K-LINES[I+1].K) >eps) Insert (Lines[i]); for (i=1;i<=n;i++) ans=min (ans,f (points[i].x)-points[i] . y); for (i=1;i<top;i++) {point p=get_intersection (*stack[i],*stack[i+1]); Ans=min (Ans,p.y-g (p.x));} printf ("%.3lf\n", ans);}



Bzoj 1038 ZJOI2008 Lookout tower half-plane intersection

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.