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

poj 3831 Open

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

poj 3831 Open

#include <stdio.h>#include <stdlib.h>#include <math.h>typedef struct point{double x,y;}point;point  P[ 25 ];double r[ 25 ];double cxcarea( point a, point b, double r1, double r2 ){double dc = sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));double r = r1<r2?r1:r2;double R = r1>r2?r1:r2;if ( dc-1e-8 > r+R ) return 0.0;if ( dc+1e-8 < R-r ) return acos(-1.0)*r*r;double a1 = acos((r*r+dc*dc-R*R)/(2.0*r*dc));double a2 = acos((R*R+dc*dc-r*r)/(2.0*R*dc));return a1*r*r+a2*R*R-dc*r*sin(a1);}int cover( int n, double R ){for ( int i = 1 ; i <= n ; ++ i ) {int flag = 1;for ( int j = 1 ; j <= n ; ++ j ) {double s1 = cxcarea( P[i], P[j], R, r[j] );double s2 = acos(-1.0)*r[j]*r[j];if ( s1*2.0 < s2 ) {flag = 0;break;}}if ( flag ) return 1;}return 0;}double b_search( int n ){double l = 0.0,r = 50000.0,m;while ( r-l > 1e-8 ) {m = (l+r)/2.0;if ( cover( n, m ) )r = m;else l = m;}return r;}int main(){int T,N;while ( scanf("%d",&T) != EOF ) while ( T -- ) {scanf("%d",&N);for ( int i = 1 ; i <= N ; ++ i )scanf("%lf%lf%lf",&P[i].x,&P[i].y,&r[i]);printf("%.4lfn",b_search(N));}}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375269.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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