poj 3873 Trick or Treat

poj 3873 Trick or Treat,第1张

poj 3873 Trick or Treat
#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>using namespace std ;const int MAXM = 5e4+5 ;const int INF = 2e5+5 ;const double MINM = 1e-10 ;double x[MAXM], y[MAXM] ;int n ;double _distance(int i, double xx){double re = y[i]*y[i] + (x[i]-xx)*(x[i]-xx) ;return sqrt(re) ;}double solve(double p){double res = 0.0 ;for( int i = 0; i < n; i++ ){double temp = _distance(i,p) ;if( res < temp ) res = temp ;}return res ;}int main(){double l, r ;while( scanf("%d",&n) != EOF ){if( n == 0 ) break ; l = INF; r = -INF ;for( int i = 0; i < n; i++ ){scanf("%lf%lf",&x[i],&y[i]) ;if( l > x[i] ) l = x[i] ; if( r < x[i] ) r = x[i] ;}while( r - l >= MINM ){double mid1 = (l+r) / 2 ;double mid2 = (l+mid1) / 2 ;double res1 = solve(mid1) ;double res2 = solve(mid2) ;if( res1 >= res2 )r = mid1 ;elsel = mid2 ;}printf("%.9lf %.9lfn",l,solve(l)) ;}return 0 ;}

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

原文地址: http://outofmemory.cn/zaji/4907652.html

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

发表评论

登录后才能评论

评论列表(0条)

保存