FZU1515 Balloons in a Box

题意:黑书 P8

注意:触及到箱子或者之前放好的气球。如果没有放好,则不算,



#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;
double xs,ys,zs,xe,ye,ze;
struct point{
    double x,y,z,r;
    void get()
    {
        scanf("%lf%lf%lf",&x,&y,&z);
        r = 0;
    }
} re[9];
int n,tmp[9];double mas;
double make1(int k)
{
    double ans = 1e20;
    ans = min(ans,min(fabs(re[k].x-xs),fabs(re[k].x-xe)));
    ans = min(ans,min(fabs(re[k].y-ys),fabs(re[k].y-ye)));
    ans = min(ans,min(fabs(re[k].z-zs),fabs(re[k].z-ze)));
    return ans;
}
inline double POW(double x)
{
    return x*x;
}
double make2(int f,int t)
{
    if(re[t].r==0) return 1e20;
    return  max(sqrt(POW(re[f].x-re[t].x)+POW(re[f].y-re[t].y)+POW(re[f].z-re[t].z))-re[t].r,0.0);
}
double PI = acos(-1.0);
int main()
{
   // freopen("in.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        scanf("%lf%lf%lf%lf%lf%lf",&xs,&ys,&zs,&xe,&ye,&ze);
        mas = 0;
        for(int i=0;i<n;i++)
        re[i].get();
        for(int i=0;i<n;i++)
        tmp[i]=i;
        for(;;)
        {
            for(int i=0;i<n;i++) re[i].r = 0;
            double v = 0;
            for(int i=0;i<n;i++)
            {
                double r = make1(tmp[i]);//cout<<"ro="<<r<<endl;
                for(int j=0;j<n;j++)
                if(j!=i)
                r = min(r,make2(tmp[i],tmp[j]));
                re[tmp[i]].r = r;
                v += r*r*r*4/3*PI;
            }
            mas = max(mas,v);
            if(!next_permutation(tmp,tmp+n)) break;
        }
        printf("%.0lf\n",fabs((xs-xe)*(ys-ye)*(zs-ze))-mas);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值