UVA 10012 How Big Is It?(暴力枚举)
| 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?(暴力枚举)的更多相关文章
- UVA 617 - Nonstop Travel(数论+暴力枚举)
题目链接:617 - Nonstop Travel 题意:给定一些红绿灯.如今速度能在30-60km/h之内,求多少个速度满足一路不遇到红灯. 思路:暴力每个速度,去推断可不能够,最后注意下输出格式就 ...
- UVA 11059 Maximum Product【三层暴力枚举起终点】
[题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- uva 11088 暴力枚举子集/状压dp
https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...
- UVA - 11464 Even Parity 【暴力枚举】
题意 给出一个 01 二维方阵 可以将里面的 0 改成1 但是 不能够 将 1 改成 0 然后这个方阵 会对应另外一个 方阵 另外一个方阵当中的元素 为 上 下 左 右 四个元素(如果存在)的和 要求 ...
- 紫书 例题 10-2 UVa 12169 (暴力枚举)
就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)
/* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...
- HNU 12886 Cracking the Safe(暴力枚举)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...
随机推荐
- js constructor 和 instanceof
说到这两个属性,那不得不说一下_proto_这个属性,通常这个属性是隐藏属性,是不允许被暴露的,而某些浏览器为了开发者能够很好的理解,而将这个属性暴露出来,比如Mozilla FireFox,这就是为 ...
- [CodeForces]CodeForces - 1025F Disjoint Triangles
题意: 给出平面上n个点,问能在其中选出6个点,组成两个三角形,使得其互不相交 问有多少种选法 大致思路 考虑枚举一条直线,将所有得点分为左右两部分,其中有两个点在直线上, 以这两个点为顶点,分别统 ...
- My blog in AI -- 梯度下降算法
人工神经网络是对生物神经网络的模仿,神经网络对一个问题的学习,需要经历数据输入.网络参数的训练.超参数的调节等部分. 这次我们来详细讨论一下神经网络的学习过程. 假设我们要训练一个神经网络去识别一张图 ...
- Python发送带附件的邮件
看别人的博客就不要在往别人的邮箱里发东西了行不行, 有点素质可以吗!!! 写出来分享还不知道珍惜!!!!! #-*-encoding:utf-8 -*- import os import smtpli ...
- [BZOJ3595][SCOI2014]方伯伯的OJ(裂点Splay)
用一棵Splay按名次维护每个点,其中一个节点对应初始编号连续的一段区间,这样总节点数是$O(m)$的. 对每个编号记录这个点被Splay的那个节点维护,用std::map存储,只记录被修改的点. 每 ...
- [HDU6198]number number number
题目大意: 给定一个数k表示你可以从包括0的斐波那契数列中任取k个数,得到它们的和.求最小的不能得到的自然数. 思路: 打表找规律,可以发现答案为f(2k+3)-1,然后用公式f(i)=f(i/2)* ...
- [HDU5343]MZL's Circle Zhou
题目大意: 给你两个字符串a和b,从中分别取出子串x和y,求不同的x+y的个数. 思路: 对于每一个字符串,构建SAM. 为了保证相同的x+y不会被重复统计,我们可以想办法只统计相同的x+y中x最长的 ...
- hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...
- C++使用new和不使用new创建对象区别
前言 在使用面向对象的时候,发现使用new和不使用new创建的对象区别还是蛮大的,做个总结: 总结 new创建的是一个指向类对象的指针,需要指针进行接收,一处初始化,多处使用,但是不用new创建的话不 ...
- Unity消息
GameObject关于Message带有三种方法, gameObject.SendMessageUpwards ("test1",4);gameObject.SendMessag ...