# UVa 10012 How Big Is It? (枚举&细节)

1.

2. 由于圆心横坐标在最右边的圆不一定与箱子最右端接触（如上图，我们的算法是保证每个圆的实际圆心横坐标尽量小，即往左边靠），所以箱子长度=max{圆实际圆心横坐标+圆的半径}

/*0.098s*/

#include<bits/stdc++.h>
using namespace std;

double a[10], r[10];

///计算圆心的实际横坐标
inline void calc(int id)
{
double x;
for (int i = 0; i < id; ++i)
{
x = sqrt((a[i] + a[id]) * (a[i] + a[id]) - (a[i] - a[id]) * (a[i] - a[id])) + r[i];
r[id] = max(r[id], x);
}
}

int main()
{
int T, n, i;
double ans, tmp;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
for (i = 0; i < n; ++i) scanf("%lf", &a[i]);
sort(a, a + n);
ans = 1e100;
do
{
memcpy(r, a, sizeof(a));
for (i = 1; i < n; ++i) calc(i);///计算圆心的实际横坐标
tmp = 0.0;
for (i = 0; i < n; ++i) tmp = max(tmp, r[i] + a[i]);///这么算是因为不一定最右边那个就靠在箱子右侧
ans = min(ans, tmp);
}
while (next_permutation(a, a + n));
printf("%.3f\n", ans);
}
return 0;
}


#### UVA - 10012 - How Big Is It? （枚举）

2015-03-24 19:48:50

#### uva 10012 How Big Is It?（枚举）

2015-02-03 17:16:55

#### uva 10012 How Big Is It?

2015-08-09 00:04:15

#### UVa 10012 - How Big Is It?

2012-09-12 18:26:37

#### uva 10012 How Big Is It?

2013-11-14 16:13:49

#### uva 10012 how big is it?

2011-10-29 20:20:52

#### uva 10012 How Big Is It?

2012-07-17 11:54:07

#### uva 10012 - How Big Is It?

2014-10-24 21:34:06

#### UVA 10012 How Big Is It?

2015-02-17 15:18:32

#### UVA 10012 How Big Is It?

2016-07-27 21:01:19