题目例如以下:

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的代码例如以下:

最新文章

  1. Redis所需内存 超过可用内存怎么办
  2. ios编码转换 国标 UTF-8
  3. 剖析简易计算器带你入门微信小程序开发
  4. 线程入门之优先级priority
  5. python编程语言缩进格式
  6. Gerrit 删除项目
  7. 2-16 HDO1106
  8. Java安全学习
  9. 201521123042 《Java程序设计》 第10周学习总结
  10. supervisor安装使用和我踩过的坑
  11. MyISAM和InnoDB区别详解
  12. css hack 用法注意
  13. 2017-2018-2 20155224『网络对抗技术』Exp5:MSF基础应用
  14. Mysql数据类型《四》日期类型
  15. web.config配置文件中的configSource属性
  16. 流畅的python 符合python风格的对象
  17. TP框架基础2
  18. Pacemaker、corosync
  19. Maven添加本地依赖
  20. iOS UIView控件的常用属性和方法的总结

热门文章

  1. 关于java堆内存溢出的几种情况(转)
  2. poj2253(最短路小变形)
  3. 孙鑫HTML视频学习总结
  4. xcode project
  5. [C++/CLI编程宝典][2]什么是C++/CLI语言
  6. shell命令批量杀死MySQL连接进程
  7. Linux系统时间和硬件时间设置
  8. HDU 1241 :Oil Deposits
  9. DirectX11 学习笔记9 - 动态顶点缓冲区 和 静态顶点缓冲区
  10. 从零开始学Xamarin.Forms(三) Android 制作启动画面