油滴扩展,洛谷之提高历练地,搜索Ex(3-1)

正题

      废话不多说因为这题有点简单。

      第二题:油滴扩展

       看到数据很开心<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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值