UVA How Big Is It?
题目例如以下:
How Big Is It? |
Ian's going to California, and he has to pack his things, including hiscollection of circles. Given a set of circles, your program mustfind the smallest rectangular box in which they fit.All circles must touch the bottom of the box. The figure below showsan
acceptable packing for a set of circles (although this may not bethe optimal packing for these particular circles). Note that in anideal packing, each circle should touch at least one other circle(but you probably figured that out).

Input
The first line of input contains a single positive decimal integer n,n<=50. This indicates the number of lines which follow. Thesubsequent
n lines each contain a series of numbers separated byspaces. The first number on each of these lines is a positive integerm,
m<=8, which indicates how many other numbers appear on thatline. The next
m numbers on the line are the radii of the circleswhich must be packed in a single box. These numbers need not beintegers.
Output
For each data line of input, excluding the first line of input containingn, your program must output the size of the smallest rectangle which canpack the circles. Each case should be output on a separate line by itself,with three places after the decimal
point. Do not output leading zeroesunless the number is less than 1, e.g.
.
0.543
Sample Input
3
3 2.0 1.0 2.0
4 2.0 2.0 2.0 2.0
3 2.0 1.0 4.0
Sample Output
9.657
16.000
12.657
求能放置所给圆的矩形的最小长度。这道题有一些细节没注意到的话就会无限WA。刚開始我想的是把全部圆全排列,把每一个情况的长度算出来求最小值,结果WA了。由于算每一个情况长度的时候。我是如果每一个圆都与前一个圆相切,实际并不一定这样。比方有两个非常大的圆相切,他们中间能够有很多小圆,与这两个圆并不一定相切。所以用之前的方法算出来结果就小了。
在网上參考了别人的代码,发现他们是设置了一个数组记录圆心坐标,求每一个圆心坐标的时候,是求出与之前圆相切的圆的圆心坐标的最大值,由于眼下考虑的圆肯定是最右的圆,所以它的圆心坐标肯定最大,又由于要矩形长度最短,所以至少与之前的某一个圆相切(不一定是前一个)。最左边的坐标就是圆心坐标减去半径大小的最小值,最右边的坐标就是圆心坐标加上半径大小的最大值,最右边减去最左边的值的最小值就是矩形的最小长度。
AC的代码例如以下:
UVA How Big Is It?的更多相关文章
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
随机推荐
- VMware中linux与window目录共享
在虚拟机下来实如今windows下共享一个目录: (前提已安装完毕vmtools:http://blog.csdn.net/pipisorry/article/details/21318931) 打开 ...
- [Backbone]Make Backbone Better With Extensions
Backbone is becoming wildly popular as a web application development framework. Along with this popu ...
- 使用xml和java代码混合控制UI界面
main.xml.................... <?xml version="1.0" encoding="utf-8"?> <Li ...
- RCP开发中错误:java.lang.RuntimeException: WARNING: Prevented recursive attempt to activate part...
在做RCP的eclipse插件开发时,启动管理软件界面时,总是报如下错误 : !ENTRY org.eclipse.ui.workbench 4 0 2012-05-25 18:44:21.306 ! ...
- Cocos2dx 3.x创建Layer的步骤
创建 1.新建类文件.注意文件夹为Classes下.否则文件不能正常找到. 2.改动预编译头.如用VS,默觉得#pragma once,为了兼容,改为#ifndef | #define | #endi ...
- young tableaus
Young tableaus 这是 Introduction_to_algorithms一个 路学校运动, 我也难倒,互联网没有找到现有的应答. 今天 python 代码贴,供你参考. #! /us ...
- Wix打包系列(七) 添加系统必备组件的安装程序
原文:Wix打包系列(七) 添加系统必备组件的安装程序 我们知道在vs的打包工程中添加系统必备组件是一件很容易的事情,那么在wix中如何检测系统必备组件并在安装过程中安装这些组件.这里以.Net Fr ...
- SE 2014年5月8日
两企业接入到 Internet(A公司和B公司),企业内部的用户及服务器均能够访问到 Internet. 2. A公司规模较大,采用了接入层/汇聚层/核心层的划分模式,接入层划分了多vLan(如图), ...
- centos安装Chromium
1. Change root user Shell su - ## OR ## sudo -i 0 1 2 3 4 su - ## OR ## sudo -i 2a. Install NCSU ...
- GDAL切割重采样遥感图像
一个小测试程序开发全过程实录,完全新手入门级的实例,如果你还在为处理大影像而发愁,来试试这个称手的工具吧. Imagec 开发日记 2013-6-25 需求: 影像数据切割,重采样 数据切割的要求是简 ...