uva 10012 - How Big Is It?
来源:互联网 发布:ali个人域名怎么转企业 编辑:程序博客网 时间:2024/06/05 14:35
Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which they fit. All circles must touch the bottom of the box. The figure below shows an acceptable packing for a set of circles (although this may not be the optimal packing for these particular circles). Note that in an ideal packing, each circle should touch at least one other circle (but you probably figured that out). each data line of input, excluding the first line of input containing n, your program must output the size of the smallest rectangle which can pack the circles. Each case should be output on a separate line by itself, with three places after the decimal point. Do not output leading zeroes unless the number is less than 1, e.g.
The first line of input contains a single positive decimal integer n, n<=50. This indicates the number of lines which follow. The subsequent n lines each contain a series of numbers separated by spaces. The first number on each of these lines is a positive integer m, m<=8, which indicates how many other numbers appear on that line. The next m numbers on the line are the radii of the circles which must be packed in a single box. These numbers need not be integers.
each data line of input, excluding the first line of input containing n, your program must output the size of the smallest rectangle which can pack the circles. Each case should be output on a separate line by itself, with three places after the decimal point. Do not output leading zeroes unless the number is less than 1, e.g. 0.543
.
3
3 2.0 1.0 2.04 2.0 2.0 2.0 2.03 2.0 1.0 4.0
9.657
16.00012.657
题意:
给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短;
#include<cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std; double a[10], r[10]; ///计算圆心的实际横坐标inline void calc(int id){ double x; for (int i = 0; i < id; ++i) { x = sqrt((a[i] + a[id]) * (a[i] + a[id]) - (a[i] - a[id]) * (a[i] - a[id])) + r[i]; r[id] = max(r[id], x); }} int main(){ int T, n, i; double ans, tmp; scanf("%d", &T); while (T--) { scanf("%d", &n); for (i = 0; i < n; ++i) scanf("%lf", &a[i]); sort(a, a + n); ans = 1e100; do { memcpy(r, a, sizeof(a)); for (i = 1; i < n; ++i) calc(i);///计算圆心的实际横坐标 tmp = 0.0; for (i = 0; i < n; ++i) tmp = max(tmp, r[i] + a[i]);///这么算是因为不一定最右边那个就靠在箱子右侧 ans = min(ans, tmp); } while (next_permutation(a, a + n)); printf("%.3f\n", ans); } return 0;}
</pre><pre name="code" class="cpp"><pre class="sh-cpp sh-sourceCode" style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding: 5px 5px 5px 7px; overflow: auto; font-size: 16px; line-height: 17.6000003814697px; font-family: 'Courier New', Courier, monospace;">
0 0
- uva 10012 how big is it?
- uva 10012 How Big Is It?
- uva 10012 - How Big Is It?
- UVa 10012 - How Big Is It?
- [uva] 10012 - How Big Is It?
- UVa 10012 - How Big Is It?
- UVa 10012 - How Big Is It?
- uva 10012 How Big Is It?
- uva 10012 - How Big Is It?
- UVA 10012 How Big Is It?
- uva 10012How Big Is It?
- UVA - 10012 How Big Is It?
- UVA 10012 How Big Is It?
- uva 10012How Big Is It?
- UVA How Big Is It?
- UVa 10012 - How Big Is It? 圆排列问题
- UVa 10012 How Big is It? (计算几何+DFS)
- UVA 10012 How Big Is It?(暴力枚举)
- IIS权限设置
- C# XMLDocument
- WPF MVVM TreeViewItem
- 计算机视觉目标检测的框架与过程
- 计算机网络协议第三章,网络层协议
- uva 10012 - How Big Is It?
- HDU 5014 Number Sequence
- ftp的web访问格式
- 安卓实现底部弹出框/自定义对话框
- java怎样得到运行时程序的行号
- 数字图像处理,小波变换一维Mallat算法的C++实现(matlab验证)
- Linux学习笔记(七)打造vim下的IDE
- 【Shell】【学习笔记】Linux Shell脚本应用(七)
- Android 获取手机SIM资料详解