正题
废话不多说因为这题有点简单。
第二题:油滴扩展
看到数据很开心<n<=6>,废话不多说暴搜。FFF(Fast,Fast,Fast)
具体做法不用多说直接看一下当前的油滴距离方框四周的距离和其他已放置油滴的距离即可,扩展之后放下一个,注意精度。
代码<不喜勿喷>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
int n;
struct now{
double x,y,r;
};
now s[10];
struct node{
double x,y;
};
node p[10];
double sx,sy,tx,ty;
double tot=0;
double max=0;
bool tf[10];
double mmin(double x,double y){
return x<y?x:y;
}
double qiu(int x,int y){
double q=sqrt((p[x].x-s[y].x)*(p[x].x-s[y].x)+(p[x].y-s[y].y)*(p[x].y-s[y].y));
if(q>=s[y].r) return q-s[y].r;
else return 0;
}
void dfs(int x){
if(x==n+1){
if(tot>max) max=tot;
return ;
}
for(int i=1;i<=n;i++){
if(tf[i]) continue;
double min=1e9;
min=mmin(min,mmin(p[i].x-sx,mmin(tx-p[i].x,mmin(p[i].y-sy,ty-p[i].y))));
for(int j=1;j<=x-1;j++)
min=mmin(min,qiu(i,j));
tot+=min*min;
s[x].x=p[i].x;
s[x].y=p[i].y;
s[x].r=min;
tf[i]=true;
dfs(x+1);
tot-=min*min;
s[x].x=0;
s[x].y=0;
s[x].r=0;
tf[i]=false;
}
}
int main(){
scanf("%d",&n);
scanf("%lf %lf %lf %lf",&sx,&sy,&tx,&ty);
if(tx<sx){
int t=sx;sx=tx;tx=t;
}
if(ty<sy){
int t=sy;sy=ty;ty=t;
}
for(int i=1;i<=n;i++){
double x,y;
scanf("%lf %lf",&x,&y);
x+=1000;y+=1000;
p[i].x=x;p[i].y=y;
}
sx+=1000;sy+=1000;tx+=1000;ty+=1000;
dfs(1);
printf("%.0lf",(tx-sx)*(ty-sy)-max*3.1415926535897932384626433832795);
}