三分模版

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <iostream>
using namespace std;
#define pb push_back
typedef long long ll;
const int N=5e4+5;
const double eps=1e-8;
double x[N],y[N];
int n;
double get_distance(int i,double xx)
{
    return sqrt(y[i]*y[i]+(x[i]-xx)*(x[i]-xx));
}
double f(double xx)
{
    double ans=0.0;
    for(int i=0; i<n; i++)
        ans=max(ans,get_distance(i,xx));
    return ans;
}
double three(double l,double r)
{
    while(l+eps<=r)
    {
        double m1=(r+l)/2,m2=(m1+r)/2;
        double res1=f(m1),res2=f(m2);
        //求最大值改成>= 最小值改成<=
        if(res1<=res2)r=m2;
        else l=m1;
    }
    printf("%f %f\n",l,f(l));
}
int main()
{
    double l, r;
    while(scanf("%d",&n)&&n)
    {
        scanf("%lf%lf",&x[0],&y[0]);
        l=r=x[0];
        for(int i=1; i<n; i++)
        {
            scanf("%lf%lf",&x[i],&y[i]);
            l=min(l,x[i]),r=max(r,x[i]);
        }
        three(l,r);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值