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();
}
}

UVA 2474 - Balloons in a Box 爆搜的更多相关文章

  1. UVALive 2474 Balloons in a Box(枚举)

    https://vjudge.net/contest/277824#problem/A 尤其是模拟题,三思而后敲!!! 纠错了好久,主要还是没有处理好:单点若还未放气球,其他气球可以膨胀越过它(即可以 ...

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

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

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

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

  4. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  5. hdu5323 Solve this interesting problem(爆搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Solve this interesting problem Time Limit ...

  6. hdu4536-XCOM Enemy Unknown(爆搜)

    XCOM-Enemy Unknown是一款很好玩很经典的策略游戏. 在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3 ...

  7. poj1077 Eight【爆搜+Hash(脸题-_-b)】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

  8. [NOIP2015] 斗地主 大爆搜

    考试的时候想了半天,实在是想不到解决的办法,感觉只能暴力..然后暴力也懒得打了,小数据模拟骗30分hhh 然而正解真的是暴力..大爆搜.. 然后我的内心拒绝改这道题(TAT) 不过在wcx大佬的帮助下 ...

  9. BZOJ 1207: [HNOI2004]打鼹鼠【妥妥的n^2爆搜,dp】

    1207: [HNOI2004]打鼹鼠 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3259  Solved: 1564[Submit][Statu ...

随机推荐

  1. structc 开源框架介绍

    引言 - 一切才刚刚开始 structc 是 C 结构基础库. 简单可复用. structc - https://github.com/wangzhione/structc 之前也描述过几次 stru ...

  2. ActiveMQ之VirtualTopic是什么?

    一句话总结: VirtualTopic是为了解决持久化模式下多消费端同时接收同一条消息的问题.   想象这样一个场景:   生产端产生了一笔订单,作为消息MessageOrder发了出去. 这笔订单既 ...

  3. MySQL缓存命中率概述及如何提高缓存命中率

    MySQL缓存命中率概述 工作原理: 查询缓存的工作原理,基本上可以概括为: 缓存SELECT操作或预处理查询(注释:5.1.17开始支持)的结果集和SQL语句: 新的SELECT语句或预处理查询语句 ...

  4. Unix IPC之基于共享内存的计数器

    目的 本文主要实现一个基于共享内存的计数器,通过父子进程对其访问. 本文程序需基于<<Unix网络编程-卷2>>的环境才能运行.程序中大写开头的函数为其小写同名函数的包裹函数, ...

  5. VS Code折腾记 - (1)扯淡

    题外话 距离上篇介绍VSCode的文章已经过去四十多天,已经在正式项目作为主力开发工具了. 社区的发展非常快速,更新迭代够快,功能基本已经满足我所需了: 这个系列教程基于最新的vs code 1.8. ...

  6. django 建立一个简单的应用

    本人的用的版本是python 2.7.3和django 1.10.5,Windows10系统 1.首先通过命令建立项目和app 找到django的安装路径,我的路径是:C:\Python27\Lib\ ...

  7. Linux基础入门学习笔记之二

    第三节 用户及文件权限管理 Linux用户管理 Linux是可以实现多用户登录的操作系统 查看用户 who命令用于查看用户 shiyanlou是当前登录用户的用户名 pts/0中pts表示伪终端,后面 ...

  8. IdentityServer4揭秘---登录

    IdentityServer4默认提供了的登录地址是Account/Index 同意页面是Consent/Index 这里我们可以通过IdentittyServer4的用户交互自定义配置设置 在Con ...

  9. hdu 5131 (2014广州现场赛 E题)

    题意:对给出的好汉按杀敌数从大到小排序,若相等,按字典序排.M个询问,询问名字输出对应的主排名和次排名.(排序之后)主排名是在该名字前比他杀敌数多的人的个数加1,次排名是该名字前和他杀敌数相等的人的个 ...

  10. centos killall安装

    https://blog.csdn.net/joeyon1985/article/details/46707865 https://blog.csdn.net/xupeng874395012/arti ...