Bzoj 1038 Zjoi 2008 observation tower half plane intersection __bzoj

Source: Internet
Author: User

The outline of a village is given, in which a watchtower can be built in any place, and the tower needs to be high enough to be able to see the full picture of the village. Ask for the minimum height of the lookout tower.


Train of thought: for every side of the village, watchtower must be in the half plane area to the left of the line in order to see it. So in order to satisfy all the needs of the side, do a half plane intersection, the highest point of Watchtower must be in all sides of the half plane intersection of the area.

The following drawing example.

The half plane intersection area of all sides is the graph above. The function relation of the upper half plane is F (x), and the function relation of the village head is G (x), then the problem is converted to an X so that (f (x)-G (x)) is minimized.

How to do this. Enumeration. Are all real numbers how to enumerate. Note that both the above and below are straight lines, and because of the monotonicity of the primary function, the extreme value of F (x)-G (x) must be obtained at both ends of the line. So we just enumerate the endpoints of the top and bottom segments.


CODE:

#include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream&
Gt #include <algorithm> #define MAX 310 #define INF 1e11 #define EPS 1e-10 #define DCMP (a) (Fabs (a) < EPS? True:fal

SE) using namespace std;

	struct point{double x,y; Point (double _ =. 0,double __ =. 0): X (_), Y (___) {} point operator-(const point &a) const {return point (X-a.x,y-
	A.Y);
	The point operator + (const point &a) is const {return point (x + a.x,y + a.y);
	The point operator * (double A) is const {return point (x * a,y * a);

}}point[max],p[max];
	struct line{point p,v;

	Double Alpha;
	Line (Point _,point __):p (_), V (__) {alpha = atan2 (v.y,v.x);
	Line () {} BOOL operator < (const-line &a) const {return Alpha < A.alpha;

}}line[max],q[max];

int points,lines;

inline void Makeline (const point &a,const point &b) {Line[++lines] = line (A,B-A); Inline double Cross (const point &a,const point &b) {return a.x * B.Y-A.Y * b.x;

} inline bool Onleft (const line &l,const point &p) {return Cross (L.V,P-L.P) > 0;}
	Inline point getintersection (the const line &a,const line &b) {point u = A.P-B.P;
	Double temp = Cross (b.v,u)/Cross (A.V,B.V);
return A.P + a.v * TEMP;
	int halfplaneintersection () {int front = 1,tail = 1;
	Q[1] = line[1]; for (int i = 2; I <= lines ++i) {While front < tail &&!
		Onleft (Line[i],p[tail-1])--tail; if (dcmp (Cross (LINE[I].V,Q[TAIL].V)) Q[tail] = Onleft (LINE[I],Q[TAIL].P)?
		Q[tail]:line[i];
		else Q[++tail] = line[i];
	if (front < tail) P[tail-1] = getintersection (Q[TAIL],Q[TAIL-1));
return tail;
	inline double Getans (int cnt) {double ans = INF;
		for (int i = 1; i < cnt; ++i) {Double x = p[i].x;
		int POS;
				for (int j = 1;j < points ++j) if (x <= point[j].x) {pos = j;
			Break Point intersection = Getintersection (line (point[pos-1],point[pos)-point[pos-1)), line (P[i),Point (0,1)));
	ans = min (ANS,P[I].Y-INTERSECTION.Y);
		for (int i = 1; I <= points ++i) {Double temp =. 0;
			for (int j = 1; J <= CNT, ++j) {point intersection = Getintersection (Q[j],line (point[i],point));
		temp = max (TEMP,INTERSECTION.Y-POINT[I].Y);
	ans = min (ans,temp);
return ans;
	int main () {CIN >> points;
	for (int i = 1; I <= points ++i) scanf ("%lf", &point[i].x);
	for (int i = 1; I <= points ++i) scanf ("%lf", &point[i].y);
	for (int i = 1; i < points ++i) Makeline (point[i],point[i + 1]);
	Sort (line + 1,line + lines + 1);
	int cnt = halfplaneintersection ();
	cout << Fixed << setprecision (3) << Getans (CNT) << Endl;
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.