luogu P1378 油滴扩展
题面传送门
这道题数据这么小,一看就是搜索,只是细节比较多。
我们思考怎么通过一个点的半径确定另一个点的半径。两点的欧几里得距离显然是\(\sqrt {(x1-x2)^2+(y1-y2)^2}\),那么减去那个点的半径\(d\),那么可得式子为\(\sqrt {(x1-x2)^2+(y1-y2)^2}-d\),但如果这个点在已知点的半径以内,那么其面积就为\(0\),所以进一步修改式子为\(max(\sqrt {(x1-x2)^2+(y1-y2)^2}-d,0)\)
代码实现:
#include<cstdio>
#include<cmath>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
int n,m,k,v[39];
double d[39],ans,x[39],y[39],lx,ly,rx,ry,p=3.141592653;
inline double find(int s){
double tot=min(min(abs(x[s]-lx),abs(rx-x[s])),min(abs(y[s]-ly),abs(ry-y[s])));
for(int i=1;i<=n;i++){
if(v[i]&&i!=s){
double now=sqrt((x[s]-x[i])*(x[s]-x[i])+(y[s]-y[i])*(y[s]-y[i]));
tot=min(tot,max(now-d[i],0.0));
}
}
return tot;
}
inline void dfs(int x,double tot){
//printf("%lf\n",tot);
if(x==n+1){ans=max(ans,tot);return;}
for(int i=1;i<=n;i++){
if(!v[i]){
v[i]=1;
d[i]=find(i);
//printf("%lf\n",d[i]);
dfs(x+1,tot+d[i]*d[i]*p);
v[i]=d[i]=0;
}
}
}
int main(){
register int i;
scanf("%d",&n);
scanf("%lf%lf%lf%lf",&lx,&ly,&rx,&ry);
lx+=1000;ly+=1000;rx+=1000;ry+=1000;
for(i=1;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]),x[i]+=1000,y[i]+=1000;
dfs(1,0);
//printf("%lf\n",ans);
printf("%d\n",((int)(abs(rx-lx)*abs(ry-ly)-ans+0.5)));
}