思路:由于n<=6,我们可以枚举油滴放置顺序的排列,然后DFS。对于每个油滴,其能扩散的最小半径为min{到四个边界的距离,到已添加的点的扩散范围的最小距离}。最后注意四舍五入:printf("%d",(int)ans+0.5);(其中ans为double类型)。
AC Code:
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const double pi=3.1415926535; int n; int a[10]; struct node{ double x,y; }o[10]; double ans=1e9; double x,y,xx,yy; double minr[10]; void dfs(int u,double res){ if(u==n+1){ ans=min(ans,res); return; } double X=o[a[u]].x,Y=o[a[u]].y; double r=min(fabs(X-x),min(fabs(X-xx),min(fabs(Y-y),fabs(Y-yy)))); for(int i=1;i<u;i++){ double xi=o[a[i]].x,yi=o[a[i]].y; double dis=sqrt((X-xi)*(X-xi)+(Y-yi)*(Y-yi)); if(dis<=minr[a[i]]){ minr[a[u]]=0; dfs(u+1,res); return ; } else { r=min(r,fabs(dis-minr[a[i]])); } } minr[a[u]]=r; dfs(u+1,res-pi*r*r); return ; } int main(){ scanf("%d",&n); scanf("%lf%lf%lf%lf",&x,&y,&xx,&yy); for(int i=1;i<=n;i++){ a[i]=i; scanf("%lf%lf",&o[i].x,&o[i].y); } double s=(fabs(xx-x)*fabs(yy-y)); do{ memset(minr,0,sizeof(minr)); dfs(1,s); }while(next_permutation(a+1,a+n+1)); printf("%d",(int)(ans+0.5)); return 0; }
原文地址:https://www.cnblogs.com/Loi-Brilliant/p/9460908.html
时间: 2024-09-30 09:02:58