2018-2019 ACM-ICPC, Asia Nanjing-D: Country Meow(三分)

Problem D. Country Meow
Input file: standard input
Output file: standard output

In the 24th century, there is a country somewhere in the universe, namely Country Meow. Due to advanced technology, people can easily travel in the 3-dimensional space.
There are N cities in Country Meow. The i-th city is located at ( x i , y i , z i ) (x_i, y_i, z_i) (xi,yi,zi) in Cartesian coordinate.
Due to the increasing threat from Country Woof, the president decided to build a new combatant command, so that troops in different cities can easily communicate. Hence, the Euclidean distance between the combatant command and any city should be minimized.
Your task is to calculate the minimum Euclidean distance between the combatant command and the farthest city.
Input
The first line contains an integer N ( 1 ≤ N ≤ 100 ) N (1 ≤ N ≤ 100) N(1N100).
The following N lines describe the i-th city located.Each line contains three integers x i , y i , z i ( − 100000 ≤ x i , y i , z i ≤ 100000 ) x_i, y_i, z_i(−100000 ≤ x_i, y_i, z_i ≤ 100000) xi,yi,zi(100000xi,yi,zi100000).
Output
Print a real number — the minimum Euclidean distance between the combatant command and the farthest city. Your answer is considered correct if its absolute or relative error does not exceed 1 0 − 3 10^{−3} 103. Formally, let your answer be a, and the jury’s answer be b. Your answer is considered correct if ∣ a − b ∣ m a x ( 1 , ∣ b ∣ ) ≤ 1 0 − 3 \frac {|a−b|}{max(1,|b|)} ≤ 10^{−3} max(1,b)ab103.
Examples
3
0 0 0
3 0 0
0 4 0
2.500000590252103
4
0 0 0
1 0 0
0 1 0
0 0 1
0.816496631812619

思路:三分x套三分y套三分z。

#include
using namespace std;
const int MAX=2e5+10;
typedef long long ll;
struct Point{double x,y,z;}p[MAX];
double dis(Point A,Point B){return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z));}
int n;
double cal(double x,double y,double z)
{
    double sum=0;
    for(int i=0;iR)l=mid;
        else r=m;
        ans=min(ans,L);
        ans=min(ans,R);
    }
    return ans;
}
double cal(double x)
{
    double l=-100000,r=100000,ans=1e18;
    for(int i=1;i<=50;i++)
    {
        double mid=(l+r)/2;
        double m=(mid+r)/2;
        double L=cal(x,mid);
        double R=cal(x,m);
        if(L>R)l=mid;
        else r=m;
        ans=min(ans,L);
        ans=min(ans,R);
    }
    return ans;
}
int main()
{
    cin>>n;
    for(int i=0;iR)l=mid;
        else r=m;
        ans=min(ans,L);
        ans=min(ans,R);
    }
    printf("%.15f\n",ans);
    return 0;
}

你可能感兴趣的:(计算几何)