zoj 3386 Trick or Treat

zoj 3386 Trick or Treat,第1张

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;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4904211.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存