uva10012(圆)
来源:互联网 发布:阿尔法淘宝宝贝下载 编辑:程序博客网 时间:2024/05/16 15:38
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. Thesubsequentn 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 nextm 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
33 2.0 1.0 2.04 2.0 2.0 2.0 2.03 2.0 1.0 4.0
Sample Output
9.65716.00012.657
刚开始读错题了,想了半天没想出来。。。
题意:是把圆放在水平线上
思路:详见代码
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>using namespace std;double r[10], M, sum;int n, t;double cdis(double a, double b) { return 2 * sqrt(a * b);//(r1+r2)^2-(r1-r2)^2两个圆心之间的距离}double pdis(double x, double y){ return sqrt(x * x + y * y);}double check(){ int i, j; double x[10], y[10], left = 0; for (i = 0; i < t; i++) { y[i] = r[i]; if (i == 0) x[i] = r[i]; else x[i] = x[i - 1] + cdis(r[i], r[i - 1]);//每个圆的初始位置是与前一个圆相切 if (x[i] < r[i])//处理左边界 x[i] = r[i]; for (j = 0; j < i; j++)//处理重叠的圆 if (r[i] + r[j] > pdis(x[i] - x[j], y[i] - y[j])) x[i] = x[j] + cdis(r[i], r[j]); if (left < x[i] + r[i]) left = x[i] + r[i]; } return left;}int main(){ scanf("%d", &n); while (n--) { M = 1000000000; scanf("%d", &t); for (int i = 0; i < t; i++) scanf("%lf", &r[i]); check(); sort (r, r + t); do { sum = check(); if (sum < M) M = sum; } while (next_permutation(r, r + t)); printf("%.3lf\n", M); } return 0;}
0 0
- uva10012(圆)
- uva10012
- UVA10012
- UVA10012
- uva10012(How Big Is It?)-简单回溯
- UVA10012把圆放进矩形的底部求矩形的最短长度
- uva10012 - How Big Is It?
- uva10012 - How Big Is It?
- UVa10012箱子得有多大
- uva10012 不是那么简单的,有陷阱!
- halcon 圆检测(识别圆、圆拟合)
- 圆(不断添加)
- 圆桌会议(圆排列)
- (八)方与圆
- 最小覆盖圆(非)
- poj2242(圆的周长)
- 自定义圆图片(2)
- 圆检测(续)- RANSAC
- truncate,delete,drop的异同点
- set -o vi
- java概述
- nyoj163phone list 字典树
- 歌尔声学笔试
- uva10012(圆)
- uboot源码分析——stage 1
- XML命名空间
- LeetCode—Length of Last Word
- 合并html中某个元素的样式
- 最长公共子序列:HDU1159 Common Subsequence
- 动态规划求解矩阵链相乘问题
- 前端不为人知的一面--前端冷知识集锦
- android关于uses-permission权限列表