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

原创 2013年12月05日 22:55:38

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=953


思路:

最多8个球,直接枚举。

注意:

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?(枚举)

uva 10012 How Big Is It? Ian's going to California, and he has to pack his things, including hi...

uva 10012 How Big Is It?

点击打开链接 (这个链接到BNUOJ上面是一样的) 题目意思:  给定m个圆的半径,现在要求找到一个矩形使得每一个球都以地面相切,要求输出最小的矩阵的长度 解题思路:  最小的圆排列问题,对于...

uva 10012 - How Big Is It?

How Big Is It?  Ian's going to California, and he has to pack his things, including his col...

UVA - 10012 How Big Is It?(全排列 堆球问题)

How Big Is It?  Ian's going to California, and he has to pack his things, including his c...

UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短。 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了。 全排列用next_per...
  • hcbbt
  • hcbbt
  • 2013年08月05日 00:19
  • 2272

UVA 10012 - How Big Is It 暴力 回溯 全排列

暴力解法 8个圆   全排列  一个个判断 回溯  也是全排列的思想  但是在进行排列的时候取一个最小的  如果还没有排完就已经比最小的还大  那么后面的所有以此为基础的答案都可以舍去 不用...

UVa Problem 10012 How Big Is It? (它有多大?)

// How Big Is It? (它有多大?) // PC/UVa IDs: 111308/10012, Popularity: B, Success rate: low Level: 3 // ...

UVA How Big Is It?

题目如下: How Big Is It?  Ian's going to California, and he has to pack his thin...

10012 How Big Is It?(****)

/* 题意:一堆小球,要求使用最小的矩形将它们全部装起来。 要求小球必须接地,至少与其他一个小球相邻 思路:涉及到状态转移,用到动态规划思想。原来通过深搜,剪枝结果WA,后来想到两个相邻小球半径相差很...

How Big Is It?

Description Ian's going to California, and he has to pack his things, including his collection of ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UVa 10012 How Big Is It? (枚举&细节)
举报原因:
原因补充:

(最多只允许输入30个字)