傳送門:http://acm.hdu.edu.cn/showproblem.php?pid=3264
給你n個圓,座標和半徑,然後要在這n個圓的圓心畫一個大圓,大圓與這n個圓相交的面積必須大於等於每個圓面積的一半,問你建在那個圓心半徑最小,為多少。
枚舉這n個圓,求每個圓的最小半徑,通過二分半徑來求,然後取這n個的最小值即可,注意點精度就OK了。
AC代碼:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s) scanf("%s",s)#define pi1(a) printf("%d\n",a)#define pi2(a,b) printf("%d %d\n",a,b)#define mset(a,b) memset(a,b,sizeof(a))#define forb(i,a,b) for(int i=a;i<b;i++)#define ford(i,a,b) for(int i=a;i<=b;i++)typedef long long LL;const int N=33;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-8;int n;struct xkn{ double x,y,r; double area;}p[22],h;double dis(xkn a,xkn b){ return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );}double fuck(xkn a,xkn b) //求兩圓的相交面積函數。{ double d=dis(a,b); if(d>=a.r+b.r) return 0; double r=(a.r>b.r?b.r:a.r); if( d<=fabs(a.r-b.r) ) return PI*r*r; double A1=acos( (a.r*a.r+d*d-b.r*b.r)/2/a.r/d ); double A2=acos( (b.r*b.r+d*d-a.r*a.r)/2/b.r/d ); double res=A1*a.r*a.r + A2*b.r*b.r; res-=sin(A1)*a.r*d; return res;}bool xiaohao(xkn h){ for(int i=0;i<n;i++) { double jiao=fuck(p[i],h); if(jiao<p[i].area/2) return false; } return true;}int main(){// freopen("input.txt","r",stdin); int T; si1(T); while(T--) { si1(n); for(int i=0;i<n;i++) { sd2(p[i].x,p[i].y); sd1(p[i].r); p[i].area=PI*p[i].r*p[i].r; } double Min=55555; for(int i=0;i<n;i++) { double l=0,r=22222,m; while((r-l)>eps) { m=(l+r)/2; h=p[i]; h.r=m; if(xiaohao(h)) r=m; else l=m; } if(Min>m) Min=m; } printf("%.4f\n",Min); } return 0;}//92539932013-09-30 19:54:36Accepted32640MS320K2260 BG++XH_Reventon