Ground beef clan match (one-third)

 

Links: https://ac.nowcoder.com/acm/contest/3006/B
Source: Cattle-off network

Title Description

Because beef clan often away matches, so a lot of the country to establish training bases, each base has a coordinate (the X-, the y-) .
This weekend, Taurus team have to go out of the game, each match point game in x -axis. Taurus team for the convenience of the game, looking for a training base to reach the maximum and minimum distances as a place to race.
The problem for the Taurus team too simple, it is up to you, you to help him count ~

Enter a description:

The first line of input data contains an integer N ( . 1 N . 1 0 0 0 0 0 ), the number of team training base beef FIG.

Next N rows, each row comprising 2 integers X, Y (-10000≤x, y≤10000) , represent the coordinates of each of the training base.

Output Description:

Output a decimal, represents the minimum value of the maximum distance from each selected to match training base.

If you answer is a, the standard answer is B, when |a-b| / max (. 1, |b|) ≦ 10 -4 , you will answer is determined to be correct.

Entry

3
0 0
2 0
0 2

Export

2

Explanation

When the (0,0) game, to a maximum distance of three training base is 2 . It may prove to be the minimum.

 

The maximum distance of minimum subject requirements, it is easy to think of using the method to do half or thirds.

This problem is relatively simple using a three-branch, the second branch is too much trouble.

 

Thirds explain: https://blog.csdn.net/weixin_43914593/article/details/103250854

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <sstream>
13 const int INF=0x3f3f3f3f;
14 typedef long long LL;
15 const  Double EPS = 1E- . 8 ;
 16  const  int MOD = 1E9 + . 7 ;
 . 17  const  int MAXN = 1E5 + 10 ;
 18 is  the using  namespace STD;
 . 19  
20 is  struct Node
 21 is  {
 22 is      int X, Y;
 23 is } the PT [ 100005 ];
 24  int n-;
 25  
26 is  Double Check ( Double X) // find the maximum value of the distance to each point 
27  {
 28      Double MAX =0;
29     for(int i=1;i<=n;i++)
30     {
31         double t=sqrt(PT[i].y*PT[i].y+(PT[i].x-x)*(PT[i].x-x));
32         MAX=max(MAX,t);
33     }
34     return MAX;
35 }
36 
37 int main()
38 {
39     #ifdef DEBUG
40     freopen("sample.txt","r",stdin);
41     #endif
42     
43     scanf("%d",&n);
44     for(int i=1;i<=n;i++)
45         scanf("%d %d",&PT[i].x,&PT[i].y);
46     double L=-10000,R=10000;
47     double mid1,mid2;
48     while(R-L>eps)    //单谷函数三分 
49     {
50         double t=(R-L)/3.0;
51         mid1=L+t;
52         mid2=R-T;
 53 is          IF (Check (mid1)> Check (mid2)) L = mid1; // extreme point in the right mid1 
54 is          the else R & lt = mid2; // extreme point in the left mid2 
55      }
 56 is      the printf ( " % .4f \ n- " , Check (MID1));
 57 is      
58      return  0 ;
 59 }

 

 

 

 

-

Guess you like

Origin www.cnblogs.com/jiamian/p/12310469.html