[Simulated annealing two-point answer] Bzoj 1038 [ZJOI2008] Observation tower _ two points

Source: Internet
Author: User
Tags stdin


Positive solution half plane intersection,%%% popoqqq:http://blog.csdn.net/popoqqq/article/details/39340759

"To determine the height of the Watchtower, we choose the binary processing for each of the two points. We enumerate the endpoints on the polyline from left to right. The line to each endpoint must be counterclockwise from left to right, or it will be obscured.

#include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <ctime

> #define EPS 1e-4 using namespace std;
	Inline char NC () {static Char buf[100000],*p1=buf,*p2=buf;
	if (P1==P2) {p2= (p1=buf) +fread (Buf,1,100000,stdin); if (P1==P2) return EOF;}
return *p1++;
	} inline void read (int &x) {char c=nc (), b=1; for (;!
	(c>= ' 0 ' && c<= ' 9 '); C=nc ()) if (c== '-') b=-1; for (x=0;c>= ' 0 ' && c<= ' 9 '; x=x*10+c-' 0 ', C=NC ());
X*=b;
	} inline int dcmp (double a,double b) {if (Fabs (a-b) <1e-5) return 0;
	if (a<b) return-1;
return 1;
	} struct point{double x,y; Point (Double x=0,double y=0): X (x), Y (y) {} friend double Cross (point p1,point p2,point p0) {return (p1.x-p0.x) * (p2.y-p0
	. Y)-(p2.x-p0.x) * (P1.Y-P0.Y);

}}p[305];
int n;
Double x1,xn;

Double ans=1e130;

Inline double rnd () {return (rand ()%1000)/1000.0;} Inline Double calc (double x) {for (int i=1;i<n;i++) if (dcmp (p[i].x,x) <=0 && dcmp (x,p[i+1].x) <=0 return p[i].y+ (P[I+1].Y-P[I].Y)/(p[i+1].x-p[i].x) * (x-p[i].x);
Point q[305];

int R;
	inline int C (point E) {r=0;
		for (int i=1;i<=n;i++) {while (R && dcmp (Cross (p[i],q[r],e), 0) >=0) r--;
	Q[++r]=p[i];
} return R;  
	} inline bool Check (point E) {for (int i=2;i<=n;i++) if (dcmp (Cross (p[i-1],p[i],e), 0) <0) return 0;
return 1;
	Inline double Bin (double x) {double l=0,r=1e11,mid;
	Double Y=calc (x);
		while (r-l>1e-5) if (Check (mid= (l+r)/2)) R=mid;
	else L=mid;
	Ans=min (ans, (l+r)/2);
Return (L+R)/2;
	inline void SA () {#define BETA. #define EPS 1e-5 Double Nx,sx,now,delta,ret;
	sx= (X1+XN)/2;
	Now=bin (SX); for (double t=xn-x1; t>eps;
		T*=beta) {nx=sx+t* (rnd () *2-1);   
		if (nx<x1 | | nx>xn) continue;
		Ret=bin (NX);
		Delta=now-ret;
	if (delta>0 | | rnd () <exp (DELTA/T)) Sx=nx,now=ret;  
	the int main () {#define CASE 2 srand (10086);
	int IX;
	Freopen ("T.in", "R", stdin); Freopen ("T.out"," W ", stdout);
	Read (n);
	for (int i=1;i<=n;i++) read (ix), P[i].x=ix;
	for (int i=1;i<=n;i++) read (ix), P[i].y=ix; x1=p[1].x;
	xn=p[n].x;
	for (int i=1;i<=case;i++) SA ();
	printf ("%.3lf\n", ans);
return 0; }


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.