# BNU 4260 Trick or Treat && ZOJ 3386 (three-point search)

Source: Internet
Author: User

"To the point of the problem" to the x-axis point to the maximum value of the minimum point to the line segment distance

"Problem-solving ideas" three-point search

Three points to find beginners can refer to this blog analysis: three points to find, write very detailed, in fact, similar to the binary search, understand how to construct, the code is not difficult to implement

Method 1:

`#include <bits/stdc++.h>using namespace Std;const double eps=1e-7;const double inf=0x3f3f3f3f;const int n=55000; int n;struct point{double x, y;} Mapp[n];d ouble dis (point a,point b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));}    Double Getmax (double x)//longest side, maximum time {double maxx=eps;    Point q={x,0};        for (int i=0;i<n;i++) {double P=dis (q,mapp[i]);    Maxx=max (MAXX,P); } return Maxx;}    int main () {//freopen ("1.txt", "R", stdin);        while (scanf ("%d", &n)!=eof) {if (n==0) break;        Double pleft=n,pright=-n;            for (int i=0;i<n;i++) {scanf ("%lf%lf", &mapp[i].x,&mapp[i].y);  Pleft=min (pleft,mapp[i].x); Left Border Pright=max (pright,mapp[i].x);//Right Border} while ((Pright-pleft) >eps) {Doubl            E mid= (Pright-pleft)/3;            Double l,r;            L=pleft+mid,r=pleft+2*mid;            if (Getmax (L) >=getmax (R)) Pleft=l;        else pright=r;  }      printf ("%.9f%.9f\n", Pleft,getmax (Pleft)); } return 0;}`

Method 2:

`#include <bits/stdc++.h>using namespace Std;const int N=55000;const double eps=1e-7;int n,m;struct point{double x, y;} Mapp[n];d ouble disget (point A,point b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));}    Double Getmax (double x) {//For maximum edge, longest time point q={x,0};    Double maxx=eps;        for (int i=0;i<n;i++) {double p=disget (q,mapp[i]);    Maxx=max (MAXX,P); } return Maxx;}    Double Solve () {//Assign the initial value, it is best to directly assign the number!    Double pleft=-200000,pright=200000;    Double Mid,midd,mid_area,midd_area;        while (pright-pleft>eps) {mid= (pleft+pright)/2.0;        Midd= (mid+pright)/2.0;        Mid_area=getmax (mid);        Midd_area=getmax (Midd);        if (Mid_area<=midd_area) Pright=midd;    else Pleft=mid; } return Midd;}        int main () {while (scanf ("%d", &n)!=eof) {if (n==0) break;        for (int i=0;i<n;i++) {scanf ("%lf%lf", &mapp[i].x,&mapp[i].y);        } double Res=solve (); printf ("%.9f%.9f\n", Res,getmAx (res)); } return 0;}`

BNU 4260 Trick or Treat && ZOJ 3386 (three-point search)

Related Keywords:

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.