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

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

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

题意。。给定t组数据。每组数据包含一个n。然后输入n个圆的半径。。

然后要计算出。最小需要多长的盒子。才能把所有圆横着放满。。

思路:暴力枚举。。由于圆最多8个。完全可以暴力。。。

就是计算长度的时候麻烦点。。我的方法是:保存下每个圆的横坐标。。圆的横坐标加半径。最大的就是当前情况所需要的盒子大小。在从所有情况中找出最小的。。。每个圆放进去。都必定会与一个圆或者左边的墙壁相切。所以找出当前圆和前面所有放置的圆的横坐标最大的就是当前圆的横坐标。。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
int t;
int n;
double minn; struct Y
{
double x;
double r;
} yuan[10]; bool cmp(Y a, Y b)
{
return a.r < b.r;
} void find()
{
double you = 0;
for (int i = 1; i <= n; i ++)
{
double maxx = 0;
for (int j = 0; j < i; j ++)
{
double dd;
if (j == 0)
dd = yuan[i].r;
else
dd = sqrt((yuan[i].r + yuan[j].r) * (yuan[i].r + yuan[j].r) - (yuan[i].r - yuan[j].r) * (yuan[i].r - yuan[j].r));
if (maxx < dd + yuan[j].x)
{
maxx = dd + yuan[j].x;
}
}
yuan[i].x = maxx;
}
double sb = 0;
for (int i = 1; i <= n; i ++)
{
if (sb < yuan[i].x + yuan[i].r)
{
sb = yuan[i].x + yuan[i].r;
}
}
if (minn > sb)
minn = sb;
} int main()
{
scanf("%d", &t);
while (t --)
{
minn = 999999999;
memset(yuan, 0, sizeof(yuan));
scanf("%d", &n);
for (int i = 1; i <= n; i ++)
{
scanf("%lf", &yuan[i].r);
}
sort(yuan + 1, yuan + n + 1, cmp);
find();
while (next_permutation(yuan + 1, yuan + n + 1, cmp))
{
for (int i = 0; i <= n; i ++)
{
yuan[i].x = 0;
}
find();
}
printf("%.3lf\n", minn);
}
return 0;
}

UVA 10012 How Big Is It?(暴力枚举)的更多相关文章

  1. UVA 617 - Nonstop Travel(数论+暴力枚举)

    题目链接:617 - Nonstop Travel 题意:给定一些红绿灯.如今速度能在30-60km/h之内,求多少个速度满足一路不遇到红灯. 思路:暴力每个速度,去推断可不能够,最后注意下输出格式就 ...

  2. UVA 11059 Maximum Product【三层暴力枚举起终点】

    [题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...

  3. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  4. uva 11088 暴力枚举子集/状压dp

    https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...

  5. UVA - 11464 Even Parity 【暴力枚举】

    题意 给出一个 01 二维方阵 可以将里面的 0 改成1 但是 不能够 将 1 改成 0 然后这个方阵 会对应另外一个 方阵 另外一个方阵当中的元素 为 上 下 左 右 四个元素(如果存在)的和 要求 ...

  6. 紫书 例题 10-2 UVa 12169 (暴力枚举)

    就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...

  7. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  8. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  9. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

随机推荐

  1. sql中的if()和ifnull() 的用法和区别

    if() 把salary表中的女改成男,男改成女: update salary set sex = if( sex = '男','女','男'); if(true,a,b),  if(false,a, ...

  2. Java反射机制demo(七)—反射机制与工厂模式

    Java反射机制demo(七)—反射机制与工厂模式 工厂模式 简介 工厂模式是最常用的实例化对象模式. 工厂模式的主要作用就是使用工厂方法代替new操作. 为什么要使用工厂模式?直接new不好吗? 直 ...

  3. dSploitzANTI渗透教程之修改MAC地址与Wifi监听器

    dSploitzANTI渗透教程之修改MAC地址与Wifi监听器 dSploitzANTI基本配置 渗透测试是一种安全性较大的工作.所以,在实施渗透测试之前进行一些简单设置.如修改MAC地址.了解网络 ...

  4. Windows 0day成功验证之ETERNALBLUE

    本帖由春秋首发~作者:神风 @春秋文阁负责人 方程式又一波0day[该贴有工具]:https://bbs.ichunqiu.com/thread-21736-1-1.html 最近一段时间出现一波高潮 ...

  5. pygame系列_箭刺Elephant游戏_源码下载

    这个游戏原名为:Chimp,我们可以到: http://www.pygame.org/docs/tut/chimp/ChimpLineByLine.html 获取到源码和详细的源码讲解 下面是我对游戏 ...

  6. CentOS7安装GNOME可视化界面和如何配置IP地址

    本人在虚拟机安装 CentOS7 1,检查一下我们已经安装的软件以及可以安装的软件,用命令 yum grouplist 2,然后安装我们需要的图形界面软件,GNOME(GNOME Desktop) 这 ...

  7. UVA 10177 Sqr/Rects/Cubes/Boxes?

    Problem J (2/3/4)-D Sqr/Rects/Cubes/Boxes? Input: standard input Output: standard output Time Limit: ...

  8. ZOJ 1940 Dungeon Master 三维BFS

    Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Desc ...

  9. 使用python解决烦人的每周邮件汇总!

    最近开始接手BI工作,其中又一个繁琐又不得不做的事,就是每周五都得汇总上个财务周的数据给运营人员! 作为一个懒人,只能把这件事交由电脑去处理了. 初步的idea:周五11点前mac自动执行汇总程序-& ...

  10. Toast信息框

    Toast组件的功能和对话框有些相似,可是使用上更简单,使用Toast组件的目的仅仅有一个,就是在屏幕上弹出一个消息窗体告知用户某个信息,并且这个窗体没有不论什么button,经过几秒钟后就会消失.假 ...