Bzoj 1038 ZJOI2008 observation tower half plane intersection __bzoj

Source: Internet
Author: User

The main effect and simulated annealing problem: see http://blog.csdn.net/popoqqq/article/details/39340759

This time with a half plane to write again ... After the half plane intersection is obtained, enumerate each point of the original and half plane intersection to find the answer

#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <
Algorithm> #define M 310 #define EPS 1e-7 using 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-&GT;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 (the const line &l1,const line &AMP;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;
	else break;
} 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", &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);
 }



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.