uva10012
来源:互联网 发布:windows掌上电脑 编辑:程序博客网 时间:2024/05/16 14:28
How Big Is It?
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).How Big Is It?
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 the decimal point. Do not output leading zeroes unless 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
Miguel Revilla
2000-08-22
单单排列是不行的,因为有可能两个大圆中间夹着一个小圆,或者最边界的小圆不与边界相切,而是处于相对中间的大圆,所以每次排列一个圆要与所有圆相切一次求最远的圆心距离,然后求各个圆所能达到的最远边界,两边的最远边界相减就是答案了
#include<stdio.h>#include<string.h>#include<iostream>#include<math.h>using namespace std;#define maxn 0xffffffffint n,vis[10];double r[10],R[10],dist[10],minn;void dfs(int x){int i,j;double ff,right,left;if(x==n){dist[0]=0;for(i=1;i<n;i++){dist[i]=0;for(j=0;j<i;j++){ff=sqrt(4*R[i]*R[j]);if(dist[i]<dist[j]+ff)dist[i]=ff+dist[j];}}right=-maxn;left=maxn;for(i=0;i<n;i++){if(dist[i]+R[i]>right)right=dist[i]+R[i];if(dist[i]-R[i]<left) left=dist[i]-R[i];}if(right-left<minn)minn=right-left;return ;}for(i=0;i<n;i++){if(!vis[i]){vis[i]=1;R[x]=r[i];dfs(x+1);vis[i]=0;}}}main(){int i,t;//freopen("D:\\u.txt","r",stdin);scanf("%d",&t);while(t--){memset(vis,0,sizeof(vis));scanf("%d",&n);for(i=0;i<n;i++)scanf("%lf",&r[i]);minn=maxn;dfs(0);printf("%.3lf\n",minn);}return 0;}
- uva10012
- UVA10012
- UVA10012
- uva10012(圆)
- uva10012 - How Big Is It?
- uva10012 - How Big Is It?
- UVa10012箱子得有多大
- uva10012 不是那么简单的,有陷阱!
- uva10012(How Big Is It?)-简单回溯
- UVA10012把圆放进矩形的底部求矩形的最短长度
- 【分享】153个国家的信息数据集(Information data set in 153 countries)
- linux c++示例
- vs2012安装 error occurred
- 改善C++ 程序的150个建议学习之建议2:避免那些由运算符引发的混乱
- FTP命令详解
- uva10012
- ASP.NET生成压缩文件(rar打包)
- 当session长时间不登录失效问题,再重登录出现两个嵌套登录页面
- JVM知识(三)---类的执行机制(上)
- CRM利用ObjectCacheManager清除当前XrmServiceContext缓存
- C# 生成SQL文追加Where条件的方法
- iPhone 基带命令
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- CSS