PKU Trick or Treat

题目链接:

http://poj.org/problem?id=3873

题解:

给你n点的坐标,让你求出这些点到x轴上一点的最大值的最小值。让你输出这个点在x轴上的x的坐标,以及离这个点最远的点的距离。
本来以为是模拟退火,结果有人说是用三分做出来的。(今天好好学了一波三分)

代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 5*1e5+10;
#define inf 1e18
#define met(a,b) memset(a,b,sizeof(a))
#define eps 1e-9
struct node
{
    double x,y;
}num[maxn];
int n;

double cal_sum(double x,double y)
{
    double ans=0;
    for(int i=0;i<n;i++)
        ans=max(sqrt((num[i].x-x)*(num[i].x-x)+(num[i].y-y)*(num[i].y-y)),ans);
    return ans;
}

int main()
{
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        double MAX=-inf,MIN=inf;
        for(int  i=0;i<n;i++)
        {
            scanf("%lf%lf",&num[i].x,&num[i].y);
            MAX=max(MAX,num[i].x);
            MIN=min(MIN,num[i].x);
        }
        double left=MIN,right=MAX,mid1=0,mid2=0;
        while(left+eps<right)
        {
            mid1=(left*2+right)/3;
            mid2=(right*2+left)/3;
            if(cal_sum(mid1,0)<cal_sum(mid2,0))
                right=mid2;
            else
                left=mid1;
        }
        //printf("%f\n",right);
        printf("%.9f %.9f\n",left,cal_sum(left, 0));
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值