https://www.luogu.org/problem/show?pid=1378
思路简单的搜索题。
但是!这题真的是让我挠心啊!
请看注释的那两行,为什么!!(表示被这样坑了一天)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define PI 3.1415926
#define PP(x) (x)*(x)
using namespace std;
int n,X0,Y0,X1,Y1;
struct H{
int x,y;
double r;
}p[10];
bool f[10];
double ans=0,s=0,dis[10][10];
double minx(double a,double b,double c,double d)
{
double k;
k=min(a,b);k=min(k,c);
k=min(k,d);return k;
}
bool check()
{
for(int i=1;i<=n;i++)
if(!f[i]) return 0;
return 1;
}
void dfs()
{
if(check()){ans=max(ans,s);return;}
double R=1e20;
for(int i=1;i<=n;i++)
if(!f[i])
{
//R=min(R,min((double)abs(p[i].x-X1),(double)abs(p[i].x-X0)));
//R=min(R,min((double)abs(p[i].y-Y1),(double)abs(p[i].y-Y0)));为什么是错的!!!!!
R=minx(abs(p[i].x-X1),abs(p[i].x-X0),abs(p[i].y-Y1),abs(p[i].y-Y0));
for(int j=1;j<=n;j++) if(j!=i&&f[j])
R=min(R,dis[i][j]-p[j].r);
if(R<0) R=0.0;
f[i]=1;p[i].r=R;s+=R*R;
dfs();
f[i]=0;p[i].r=0;s-=R*R;
}
}
int main()
{
scanf("%d",&n);
scanf("%d%d%d%d",&X0,&Y0,&X1,&Y1);
for(int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y),p[i].r=0;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)
dis[i][j]=sqrt(PP(p[i].x-p[j].x)+PP(p[i].y-p[j].y));
dfs();
double S=(double)abs(X0-X1)*abs(Y0-Y1);
ans=S-ans*PI;
printf("%d",(int)(ans+0.5));
return 0;
}