http://acmpj.zstu.edu.cn/JudgeOnline/showproblem?problem_id=3795
淫荡的大圆旁边很小圆。。。
#include<stdio.h> #include<stdlib.h> #include<math.h> #define len 10 double radius[len],r[len],x[len],min; int n; int cmp(const void *a,const void *b) { return *(double *)a>*(double *)b?1:-1; } double dis(int past,int now) { return x[past]+2*sqrt(r[past]*r[now]); } void dfs(int cur,double num) { int i,j,c1,c2; double max,length; if(cur==n) { if(min>num) min=num; return; } for(i=0;i<n;i++) if(!i||radius[i]!=radius[i-1]) { c1=c2=0; for(j=0;j<n;j++) if(radius[i]==radius[j]) c1++; for(j=0;j<cur;j++) if(radius[i]==r[j]) c2++; if(c1>c2) { r[cur]=radius[i]; if(cur) { for(j=0,max=0.;j<cur;j++) { length=dis(j,cur); if(max<length) max=length; } if(r[cur]>max) { for(j=0;j<cur;j++) x[j]+=r[cur]-max; x[cur]=r[cur]; } else x[cur]=max; } else x[cur]=r[cur]; if(num<x[cur]+r[cur]) dfs(cur+1,x[cur]+r[cur]); else dfs(cur+1,num); } } } int main(void) { int cas,i; scanf("%d",&cas); while(cas--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf",&radius[i]); min=100000000.; qsort(radius,n,sizeof(radius[0]),cmp); dfs(0,0.0); printf("%.3lf\n",min); } return 0; }