uva 10012 How Big Is It?(枚举)
2015-02-03 17:16
330 查看
uva 10012 How Big Is It?
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).
Input
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.
Output
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 can pack the circles. Each case should be output on a separate line by itself, with three places after thedecimal point. Do not output leading zeroes unless 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
题目大意:给出一些圆的 半径,求出可以装下这下这些圆的矩形箱子的最小尺寸(宽度)。圆都要与矩形底边相切。
解题思路:枚举所有情况,主要是将圆的半径转化为实际x坐标。
#include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> #include<stdlib.h> using namespace std; double p[10], r[10], ans, temp; int n; void getPos(int id) { double x; for (int i = 0; i < id; ++i) { x = sqrt((r[i] + r[id]) * (r[i] + r[id]) - (r[i] - r[id]) * (r[i] - r[id])) + p[i]; p[id] = max(p[id], x); } } int main() { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lf", &r[i]); sort(r, r + n); ans = 0xFFFFFFFF; do { memcpy(p, r, sizeof(p)); for (int i = 1; i < n; i++) { getPos(i); //计算该圆圆心的x轴坐标 } temp = 0.0; for (int i = 0; i < n; i++) { temp = max(temp, r[i] + p[i]); } ans = min(ans, temp); } while (next_permutation(r, r + n)); //枚举不同排列顺序 printf("%.3f\n", ans); } return 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? (计算几何+DFS)
- UVa Problem 10012 How Big Is It? (它有多大?)
- uva 10012 How Big Is It? (greedy + enumerate)
- 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?(下一个排序 + DFS)
- 【UVA】10012 - How Big Is It?(暴力)
- UVa 10012 How Big Is It? (枚举&细节)
- UVA10012 - How Big Is It?
- UVa 10012 - How Big Is It?