博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA How Big Is It?
阅读量:7301 次
发布时间:2019-06-30

本文共 1741 字,大约阅读时间需要 5 分钟。

题目例如以下:

 
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).

 

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 integer
m,
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.

 

For each data line of input, excluding the first line of input containing
n, 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.

 

33 2.0 1.0 2.04 2.0 2.0 2.0 2.03 2.0 1.0 4.0

 

9.65716.00012.657

求能放置所给圆的矩形的最小长度。这道题有一些细节没注意到的话就会无限WA。刚開始我想的是把全部圆全排列,把每一个情况的长度算出来求最小值,结果WA了。由于算每一个情况长度的时候。我是如果每一个圆都与前一个圆相切,实际并不一定这样。比方有两个非常大的圆相切,他们中间能够有很多小圆,与这两个圆并不一定相切。所以用之前的方法算出来结果就小了。

在网上參考了别人的代码,发现他们是设置了一个数组记录圆心坐标,求每一个圆心坐标的时候,是求出与之前圆相切的圆的圆心坐标的最大值,由于眼下考虑的圆肯定是最右的圆,所以它的圆心坐标肯定最大,又由于要矩形长度最短,所以至少与之前的某一个圆相切(不一定是前一个)。最左边的坐标就是圆心坐标减去半径大小的最小值,最右边的坐标就是圆心坐标加上半径大小的最大值,最右边减去最左边的值的最小值就是矩形的最小长度。

AC的代码例如以下:

转载地址:http://ngynm.baihongyu.com/

你可能感兴趣的文章
C#获取获取北京时间多种方法
查看>>
动态语言的灵活性是把双刃剑 -- 以 Python 语言为例
查看>>
1. 字节序的转换
查看>>
ubuntu14.04LTS下ECLIPSE+JAVA搭建
查看>>
学习RxJS: 导入
查看>>
PowerDesigner大小写转换
查看>>
纯 CSS 利用 label + input 实现选项卡
查看>>
Ubuntu 上安装R
查看>>
How .Net code can call unmanaged code?
查看>>
Archlinux安装配置以及遇到的问题
查看>>
怎么写出好代码——坏味道
查看>>
Java将CST的时间字符串转换成需要的日期格式字符串
查看>>
cisco 查看接口进出流量
查看>>
Dhcp+nfs+tftp+ks 完全无人值守安装linux操作系统
查看>>
TemplateDirectiveModel接口execute方法参数说明
查看>>
Js删除数组重复元素的多种方法
查看>>
att与intel风格对照实例
查看>>
backpack
查看>>
【转+分析】JAVA: 为什么要使用"抽象类"? 使用"抽象类"有什么好处?
查看>>
df 发现满盘
查看>>