hoj2798 Globulous Gumdrops
Globulous Gumdrops
| My Tags | (Edit) |
|---|
| Source : 2008 Stanford Programming Contest | |||
| Time limit : 1 sec | Memory limit : 64 M | ||
Submitted : 174, Accepted : 94
Description
Gwen just bought a bag of gumdrops! However, she does not like carrying gumdrops in plastic bags; instead, she wants to pack her gumdrops in a cylindrical tube of diameter d. Given that each of her gumdrops are perfect spheres of radii r1, r2, . . . , rn, find the shortest length tube Gwen can use to store her gumdrops.

You should assume that the gumdrop radii are sufficiently large that no three gumdrops can be simultaneously in contact with each other while fitting in the tube. Given this restriction, it may be helpful to realize that the gumdrops will always be packed in such a way that their centers lie on a single two-dimensional plane containing the axis of rotation of the tube.
Input
The input file will contain multiple test cases. Each test case will consist of two lines. The first line of each test case contains an integer n (1 <= n <= 15) indicating the number of gumdrops Gloria has, and a floating point value d (2.0 <= d <= 1000.0) indicating the diameter of the cylindrical tube, separated by a space. The second line of each test case contains a sequence of n space-separated floating point numbers, r1 r2 . . . rn (1.0 <= ri <= d/2) are the radii of the gum drops in Gloria's bag. A blank line separates input test cases. A single line with the numbers "0 0" marks the end of input; do not process this case.
Output
For each input test case, print the length of the shortest tube, rounded to the nearest integer.
Sample Input
2 98.1789
42.8602 28.7622
3 747.702
339.687 191.953 330.811
0 0
Sample Output
138
1628
/*
可以用dp[state][i]表示所用球状态为state,且最上面一个是第i个球,要放入这些球所需要的最大高度,那么每次加入一个球就可以转移了,状态转移方程为dp[state1][j]=min(dp[state1 ][j],jisuan(dp[state][i],i,j) );state1=state|( 1<<(j-1) );
*/
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
double r[],d,dp[<<][];
int n;
double count(double pre,int now,int top){
double x=r[top]+r[now];
double y=d-r[top]-r[now];
return pre+r[top]-r[now]+sqrt(x*x-y*y);
}
int main(){
while(scanf("%d%lf",&n,&d)!=EOF){
if(n==&&d==)return ;
for(int i=;i<=n;i++)scanf("%lf",&r[i]);
//memset(dp,127/3,sizeof(dp));
for(int i=;i<(<<n);i++){
for(int j=;j<=n;j++){
dp[i][j]=0x7fffffff;
}
}
for(int i=;i<=n;i++)dp[<<(i-)][i]=r[i]*;
for(int state=;state<(<<n);state++){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(state&(<<(j-)))continue;
int state1=state|(<<(j-));
//cout<<count(dp[state][i],i,j)<<endl;
dp[state1][j]=min(dp[state1][j],count(dp[state][i],i,j));
}
}
}
double ans=0x7fffffff;
for(int i=;i<=n;i++){
ans=min(ans,dp[(<<n)-][i]);
}
int Ans=(int)(ans+0.5);
printf("%d\n",Ans);
}
}
hoj2798 Globulous Gumdrops的更多相关文章
- 学习笔记:状态压缩DP
我们知道,用DP解决一个问题的时候很重要的一环就是状态的表示,一般来说,一个数组即可保存状态.但是有这样的一些题 目,它们具有DP问题的特性,但是状态中所包含的信息过多,如果要用数组来保存状态的话需要 ...
- 智课雅思词汇---二十五、形容词后缀-ate-fic-ose-ulent-olent-ous-ulous-y
智课雅思词汇---二十五.形容词后缀-ate-fic-ose-ulent-olent-ous-ulous-y 一.总结 一句话总结: 1.形容词后缀-ate(determinate)? determi ...
随机推荐
- SVN经常使用命令总结(持续更新)
如今流行的协同管理工具预计就属SVN和Git了.这两者都使用过,只是如今正在使用的是SVN.故将常常使用的命令总结下来. 无论是Windows端的svnclient还是eclipse的subversi ...
- php 批量删除数据
php 批量删除数据 :比如我们在看邮箱文件的时候,积攒了一段时间以后,看到有些文件没有用了 这时候我们就会想到把这些 没用的文件删除,这时候就用到了批量删除数据的功能,这里我是用了数据库原有的一个表 ...
- spring applicationContext.xml详解及模板
applicationContext.xml 文件 1.<context:component-scan base-package="com.eduoinfo.finances.ba ...
- c#4.5新语法--自动属性和隐式类型
1.自动属性 自动属性是c#中属性定义的两种形式的一种:传统属性定义.自动属性. 1.1 传统属性定义 private int _age; public int ...
- lateral inhibition
http://www.indiana.edu/~p1013447/dictionary/lat_i.htm [This means that neighboring visual neurons re ...
- DuiLib笔记之Window常用属性
caption 可拖拽以移动窗口的标题区,类型:RECT.例如,要指定标题区高度为35,可设置caption="0,0,0,35" mininfo 窗口最小尺寸,类型:SIZE.例 ...
- Interpreter Pattern
1.Interpreter模式的目的就是提供一个一门定义语言的语法表示的解释器,然后通过这个解释器来解释语言中的句子. 2.Interpreter模式结构图 3.实现 #ifndef _CONTEXT ...
- java中如何创建带路径的文件
请教各位大侠了,java中如何创建带路径的文件,说明下 这个路径不存在 ------回答--------- ------其他回答(2分)--------- Java code File f = new ...
- SDUT OJ 之 1571 《人品,有没有?》 字符串的处理问题
人品,有木有? Time Limit: 1000ms Memory limit: 32768K 有疑问?点这里^_^ 题目描述 新一届的山东理工大学ACM网络擂台赛就要开始啦!听说晋级的选手有机 ...
- Java Web 项目打包脚本
可用于 (但不限于) Eclipse 项目. 一次性生成:1. Java doc .zip 包:2. Java 源代码 .zip 包:3. Java 二进制文件 .jar 包:4. Java 源代码加 ...