UVA 2474 - Balloons in a Box 爆搜

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/357166.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

15K的前端应届毕业生,就因为掌握了这些知识点!(前端企业级开发必备)

目录 1.前端开发 下载安装VScode 优化配置 2、插件安装 3、设置字体大小 4、开启完整的Emmet语法支持 5、视图 2.Node.js 入门 2.1、什么是Node.js 2.2、Node.js有什么用 2.3、安装 下载&#xff1a; 2.4、快速入门 2.5、服务器端应用开发 3、ES6入门 3.2、let声…

[Training Video - 1] [Selenium Basics] [Download and Install Selenium]

Download Selenium Jars Configure jars in eclipse Webdriver http://docs.seleniumhq.org/download/ Selenium RC http://code.google.com/p/selenium/downloads/detail?nameselenium-remote-control-1.0.3.zip&can2&q转载于:https://www.cnblogs.com/MasterMonkInT…

【0元试用微软 Azure人工智能认知服务】这个人脸识别功能太强大啦

导读&#xff1a;这个由美丽的客服小姐姐提前申请好了企业试用的账号&#xff0c;个人的话还得需要visa卡。 官网地址&#xff1a;azure.cn 登录地址&#xff1a;portal.azure.cn 目录 1.简介 2.Azure 认知服务是什么&#xff1f; ​ 3.认知服务的四种职能 4.人脸API 5.新建一…

OpenMap教程3 –使用MapHandler构建基本的地图应用程序–第2部分

1.简介 在上一教程中&#xff0c;我们看到了MapHandler如何将各种组件连接在一起&#xff08;更具体地说&#xff0c;是从MapHandlerChild派生的类&#xff09;。 我们看到了如何以编程方式执行此操作&#xff0c;但是还有另一种声明性地使用openmap.properties 。 样本OpenMa…

《javaScript100例|01》超级经典一套鼠标控制左右滚动图片带自动翻滚

目录 HTML示例 图片示例 HTML示例 <html > <head> <meta http-equiv"Content-Type" content"text/html; charsetgb2312" /> <title>超级经典一套鼠标控制左右滚动图片带自动翻滚</title> <style type"text/css&quo…

jsf集成spring_Spring和JSF集成:MVC螺母和螺栓

jsf集成spring过去&#xff0c;我曾尝试将JSF与Spring MVC集成在一起&#xff0c;尽管我的第一次尝试成功了&#xff0c;但这远非理想。 这次&#xff0c;我决定做出一些关键决定来帮助我集中精力&#xff1a; 向后兼容。 支持JSF 1.2涉及的工作太多&#xff0c;而Spring 3.1中…

[BZOJ1007] [HNOI2008] 水平可见直线 (凸包)

Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则Li为被覆盖的. 例如,对于直线:L1:yx; L2:y-x; L3:y0 则L1和L2是可见的,L3是被覆盖的. 给出n条直线,表示成yAxB的形式(|A|,|B|<500000),且n条直线两…

《javaScript100例|02》超级经典一套鼠标控制左右滚动图片带自动翻滚

目录 效果图 JS示例 源码地址&#xff1a; 效果图 JS示例 <title>JavaScript切换图片</title> <script> function showDaTu(src){ document.getElementById("defaultImg").srcsrc; } </script> <img src"wall1.jpg" id"…

抽象工厂设计模式示例

本文是我们名为“ Java设计模式 ”的学院课程的一部分。 在本课程中&#xff0c;您将深入研究大量的设计模式&#xff0c;并了解如何在Java中实现和利用它们。 您将了解模式如此重要的原因&#xff0c;并了解何时以及如何应用模式中的每一个。 在这里查看 &#xff01; 目录 …

《javaScript100例|03》自写javaScript+CSS轮显效果

目录 效果图 代码示例 源码地址&#xff1a;自写JsCSS轮显效果.rar-互联网文档类资源-CSDN下载https://download.csdn.net/download/weixin_41937552/37380520 效果图 代码示例 <html xmlns"http://www.w3.org/1999/xhtml"> <head> <meta http-equ…

linux shell 指令 诸如-d, -f, -e之类的判断表达式

文件比较运算符-e filename 如果 filename存在&#xff0c;则为真 [ -e /var/log/syslog ]-d filename 如果 filename为目录&#xff0c;则为真 [ -d /tmp/mydir ]-f filename 如果 filename为常规文件&#xff0c;则为真 [ -f /usr/bin/grep ]-L filename 如果 filenam…

《javaScript100例|04》自动播放——Js幻灯片缓冲效果

目录 效果图 示例 源码地址&#xff1a; 效果图 示例 <html> <head> <title>自动播放——幻灯片缓冲效果</title> <style> body,div,ul,li{margin:0;padding:0;} ul{list-style-type:none;} body{background:#000;text-align:center;font:12p…

每周必写

这周没有上课&#xff0c;阅读了《代码大全》第六章模块化设计 内聚性和耦合性 模块化设计的目标是使每个子程序都成为一个“黑盒子”&#xff0c;你知道进入盒子和从盒子里出来 的是什么&#xff0c;却不知道里边发生什么。它的接口非常简单&#xff0c;功能明确&#xff0c;对…

eclipse鼠标变十了_Eclipse在过去十年中的主要成就

eclipse鼠标变十了正如我所写的那样 &#xff0c;Eclipse在11月庆祝了10年来的开源和社区。 Eclipse社区已经形成了许多里程碑 &#xff0c;但是主要成就是什么&#xff1f; Eclipse为实际改变软件行业做了什么&#xff1f; 这是我认为Eclipse的一些关键成就。 1.主导的Java ID…

vue安装教程及简介

Vue.js 是一套构建用户界面的渐进式框架。只关注视图层, 采用自底向上增量开发的设计。 目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。Vue 学习起来非常简单。 目录 常用的vue.js版本及方法 学习vue之前需要掌握基础html+css+javaScript知识。 比如: …

Spring和Amazon Web Services

如今&#xff0c; Amazon Web Services &#xff08;或AWS&#xff09;是要使用和部署到的基础架构和硬件提供商的最常见选择之一。 许多Spring应用程序已经解决了集成应用程序基础结构和底层的挑战。 这些内部解决方案在设计和实际功能方面在复杂性和复杂程度方面有所不同。 这…

学习进度条15

第十五周 所花时间&#xff08;包括上课&#xff09; 周一上午 8&#xff1a;00-9&#xff1a;50 上课 周一下午 13&#xff1a;00-14&#xff1a;00阅读人月神话 周五下午 15&#xff1a;30-17&#xff1a;30 整理本月期的所有作业 周六上午10&#xff1a;00-12&#xff1a;…

vue目录结构及简单的开发介绍

熟悉vue项目的目录结构,在一定程度上能提高我的开发效率及查找文件的速度。 这里比较推荐使用VS code编译器,HBuild-x,webstorm等编译器相比之下逊色不少,用过的就知道有多香。 目录 Vue.js 目录结构 目录说明 VUE入门基本操作 Vue.js 模板语法

PHP+jquery 树状菜单

本项目开发过程中涉及树状菜单&#xff0c;于是做如下分享菜单实现 不足之处请大牛指点并见谅&#xff08;如图&#xff09; 1&#xff1a;数据表涉及字段 id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 系统菜单ID, pid int(10) DEFAULT NULL COMMENT 父级ID, name va…

vue条件语句与循环语句的基本使用

目录 Vue.js 条件语句 Vue.js 循环语句 Vue.js 条件语句 条件判断使用 v-if 指令 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 测试实例 - 孙叫兽的博客</title> <script src="https://cdn.s…