栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3386 Trick or Treat

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3386 Trick or Treat

#include<iostream>#include<cstdio>#include<cmath>using namespace std;const double eps=1e-10;struct Point{    double x,y;};double dis(Point a,Point b){    return sqrt(0.0+(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}Point pos[60000];int n;double f(double x){    double _max=-800000;    Point t={x,0};    for(int i=0;i<n;i++)    {        double tn=dis(t,pos[i]);        _max=_max>tn?_max:tn;    }    return _max;}int main(){    while(scanf("%d",&n)==1&&n)    {        double a=800000,b=-800000;        for(int i=0;i<n;i++)        { scanf("%lf%lf",&pos[i].x,&pos[i].y); a=a<pos[i].x?a:pos[i].x; b=b>pos[i].x?b:pos[i].x;        }        while((b-a)>eps)        { double deta=(b-a)/3; double l,r; l=a+deta,r=a+2*deta; if(f(l)>=f(r)) a=l; else b=r;        }        printf("%.9lf %.9lfn",a,f(a));    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/370526.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号