2474 - Balloons in a Box

题目连接:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=99999999&page=show_problem&category=36&problem=475&mosmsg=Submission+received+with+ID+1967446

Description

You must write a program that simulates placing spherical balloons into a rectangular box.
The simulation scenario is as follows. Imagine that you are given a rectangular box and a set of
points. Each point represents a position where you might place a balloon. To place a balloon at a
point, center it at the point and inflate the balloon until it touches a side of the box or a previously
placed balloon. You may not use a point that is outside the box or inside a previously placed balloon.
However, you may use the points in any order you like, and you need not use every point. Your objective
is to place balloons in the box in an order that maximizes the total volume occupied by the balloons.
You are required to calculate the volume within the box that is not enclosed by the balloons.

Input

The input consists of several test cases. The first line of each test case contains a single integer n
that indicates the number of points in the set (1 ≤ n ≤ 6). The second line contains three integers
that represent the (x, y, z) integer coordinates of a corner of the box, and the third line contains the
(x, y, z) integer coordinates of the opposite corner of the box. The next n lines of the test case contain
three integers each, representing the (x, y, z) coordinates of the points in the set. The box has non-zero
length in each dimension and its sides are parallel to the coordinate axes.
The input is terminated by the number zero on a line by itself.

Output

For each test case print one line of output consisting of the test case number followed by the volume of
the box not occupied by balloons. Round the volume to the nearest integer. Follow the format in the
sample output given below.
Place a blank line after the output of each test case.

Sample Input

2
0 0 0
10 10 10
3 3 3
7 7 7
0

Sample Output

Box 1: 774

Hint

题意

将n个气球放到一个长方体盒子里面, 然后气球会一直膨胀, 直到碰到盒壁或者其他气球. 先要求你找到一个放气球的顺序, 使得最后最后气球占据的体积最大.

数据规模: 1≤n≤6

题解:

直接爆搜就好了,数据范围很小……

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 10;
const double eps = 1e-8;
const double pi = acos(-1.0);
double sqr(double x)
{return x*x;
}
double dis(double x1,double y11,double z1,double x2,double y2,double z2)
{return sqrt(sqr(x1-x2)+sqr(y11-y2)+sqr(z1-z2));
}
int n;
double x[maxn],y[maxn],z[maxn],ans,r[maxn];
int vis[maxn],u[maxn],cas;
double x1,y11,z1,x2,y2,z2,a,b,c;
void QAQ()
{memset(vis,0,sizeof(vis));
}
void dfs(int cnt,double v)
{if(cnt>=n){ans=min(ans,v);return;}for(int i=0;i<n;i++){if(vis[i])continue;vis[i]=1,u[cnt]=i;r[cnt]=min(x[i],a-x[i]);r[cnt]=min(r[cnt],min(y[i],b-y[i]));r[cnt]=min(r[cnt],min(z[i],c-z[i]));for(int j=0;j<cnt;j++){double d = dis(x[i],y[i],z[i],x[u[j]],y[u[j]],z[u[j]]);r[cnt]=min(r[cnt],d-r[j]);}r[cnt]=max(r[cnt],0.0);dfs(cnt+1,v-4.0/3.0*pi*r[cnt]*r[cnt]*r[cnt]);vis[i]=0;}
}
void TAT()
{cas++;scanf("%lf%lf%lf%lf%lf%lf",&x1,&y11,&z1,&x2,&y2,&z2);a=fabs(x1-x2),b=fabs(y11-y2),c=fabs(z1-z2);x1=min(x1,x2),y11=min(y11,y2),z1=min(z1,z2);for(int i=0;i<n;i++){scanf("%lf%lf%lf",&x[i],&y[i],&z[i]);x[i]-=x1,y[i]-=y11,z[i]-=z1;}ans=a*b*c;dfs(0,a*b*c);printf("Box %d: %.0f\n\n",cas,round(ans+eps));
}
int main()
{while(scanf("%d",&n)!=EOF){if(n==0)break;QAQ();TAT();}
}

转载于:https://www.cnblogs.com/qscqesze/p/5567636.html

UVA 2474 - Balloons in a Box 爆搜相关推荐

  1. 容斥 + 爆搜打表 ---- 2020年南京icpc H.Harmonious Rectangle

    题目链接 题目大意: 就是给你一个二维平面{(x,y)∣1≤x≤n,1≤y≤m}\{(x,y)|1\leq x\leq n,1\leq y \leq m\}{(x,y)∣1≤x≤n,1≤y≤m},你现 ...

  2. 1103 Integer Factorization (30 分)【难度: 中 / 爆搜】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805364711604224 爆搜的做法,动态规划也可以做,有时间也一个动 ...

  3. 1096 Consecutive Factors (20 分)【难度: 一般 / 爆搜 数论】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 注意测试点1: 72=2*3*3*4 我这里 ...

  4. POJ 1166 The Clocks (爆搜 || 高斯消元)

    题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...

  5. hdu 5031 Lines 爆搜

    事实上嘞,这个线能够仅仅延伸一端 然后嘞,爆搜一次就能够 最后嘞,600-800ms过 本弱就是弱啊.你来打我呀-- #include<iostream> #include<cstr ...

  6. 【BZOJ-18532393】幸运数字Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MB Submit: 1817  Solved: 665 [Submit][Statu ...

  7. Java实现 蓝桥杯 算法训练 Balloons in a Box

    试题 算法训练 Balloons in a Box 问题描述 你要写一个程序,使得能够模拟在长方体的盒子里放置球形的气球. 接下来是模拟的方案.假设你已知一个长方体的盒子和一个点集.每一个点代表一个可 ...

  8. 第46届icpc 沈阳 J-Luggage Lock(思维 + 爆搜 / 队友玄学出法, 还没看懂)

    第46届icpc 沈阳 J-Luggage Lock(思维 + 爆搜 / 队友玄学出法, 还没看懂) 题目来源:第46届icpc 沈阳 J-Luggage Lock 题意: 给出两个四位数的密码锁a和 ...

  9. 【ZSTU4210 2015年12月浙理工校赛 A】【DFS爆搜】孙壕请一盘青岛大虾呗 n个消费点m个购物点最后一位置恰好消费完

    4210: 孙壕请一盘青岛大虾呗 Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 585  Solved: 249 Description 话说那一年z ...

最新文章

  1. mysql路径查找_如何在MySQL的具有文件路径的列中查找和替换?
  2. MHA故障切换和在线手工切换原理
  3. 永恒边境白羊座服务器维护,永恒边境升级攻略 速升50级技巧
  4. HDFS-文件读写过程
  5. nyoj 作业题 dp
  6. oracle狎鸥亭_卢永佑 个人主页 - 韩国奥拉克皮肤科整外科 - 美佳网
  7. 20210307:力扣第231周周赛(上)
  8. ROSTCM6情感分析结果乱码
  9. Axure Rp8激活码
  10. 2021暑期实习:网易互娱游戏测试最新面经!
  11. mac怎么无线打印机连接到服务器,Mac连接打印机的方法
  12. 软件项目开发中各岗位职责
  13. 罗马音平假名中文可复制_日语五十音该怎么写呢?易混淆的五十音
  14. __attribute__((__aligned__(n)))对结构体对齐的影响
  15. Sicily1059-Exocenter of a Trian
  16. 软考网络工程师难考吗?
  17. 牛客练习赛52 B:Galahad(树状数组维护区间不同元素和(个数))
  18. oracle把数据分开,Oracle初学者入门指南-系统与用户数据分离
  19. Footprint:Curve何以在DEX赛道遥遥领先
  20. 盲盒包装流水线(数据结构实践-栈)

热门文章

  1. 【WebRTC---入门篇】(十一)STUN协议
  2. java 插入mysql 日期_Java日期-插入数据库
  3. html 图片剪裁压缩,HTML5 canvas实现图片拉伸、压缩与裁剪
  4. html弹窗代码y\/n,Nodejs扩展,实现消息弹窗(示例代码)
  5. slf4j注解log报错_SpringBoot自定义日志注解,用于数据库记录操作日志,你用过吗?...
  6. python选项卡中文详细说明_pycharm窗口选项卡管理
  7. 自制串口示波器小工具
  8. ubuntu的home目录下,Desktop等目录消失不见
  9. 网络交换机的作用有哪些?
  10. 【渝粤教育】国家开放大学2019年春季 2773特种动物养殖 参考试题