UVA 10012 How Big Is It?
来源:互联网 发布:筑山殿 知乎 编辑:程序博客网 时间:2024/06/01 09:23
UVA 10012 How Big Is It?
题目大意:给出一组圆的半径,这组圆排成一排,要求都切于底面,求要用最少长为多少的长方形能装下它们
解题思路:先全排列,然后回溯
注意点:每个圆不能只计算与上一个圆间的距离,因为可能上个圆可能很小导致圆直接与上上个圆相切而不接触上一个圆,同理,最后也不能直接加上最后一个圆的半径,因为可能最后一个圆特别小
所以每次访问一个圆时计算前几个圆与它的距离更新坐标,再加上那个圆的半径,取最大值作为长度
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>using namespace std;int m;double l;double num[10];double num2[10];double ma;void dfs(int a) { if(a == m) { if(ma < l || l == -1) l = ma; return; } double y = num[a]; for(int i = a-1; i >= 0; i--) { double x1 = pow(num[a]+num[i], 2); double x2 = pow(num[a]-num[i], 2); double x = sqrt(x1 - x2) + num2[i]*1.0; if(x > y) { y = x; } } num2[a] = y; if(num2[a] + num[a] > ma) ma = num2[a] + num[a]; dfs(a+1);}int main() { int n; cin >> n; while(n--) { cin >> m; for(int i = 0; i < m; i++) cin >> num[i]; sort(num, num+m); l = -1; while(1) { ma = 0; dfs(0); if(!next_permutation(num, num+m)) break; } printf("%.3lf\n", l); } return 0;}
0 0
- uva 10012 how big is it?
- uva 10012 How Big Is It?
- uva 10012 - How Big Is It?
- UVa 10012 - How Big Is It?
- [uva] 10012 - How Big Is It?
- UVa 10012 - How Big Is It?
- UVa 10012 - How Big Is It?
- uva 10012 How Big Is It?
- uva 10012 - How Big Is It?
- UVA 10012 How Big Is It?
- uva 10012How Big Is It?
- UVA - 10012 How Big Is It?
- UVA 10012 How Big Is It?
- uva 10012How Big Is It?
- UVA How Big Is It?
- UVa 10012 - How Big Is It? 圆排列问题
- UVa 10012 How Big is It? (计算几何+DFS)
- UVA 10012 How Big Is It?(暴力枚举)
- PHP微信支付开发
- py学习之路3-数值
- datatable 行定时查询功能
- input 使用
- 加快activity显示速度,提高用户体验
- UVA 10012 How Big Is It?
- 909422229__程序员必须知道的8大排序和3大查找
- 派生类的构造函数
- 安装mysql驱动及连接数据库
- 4.3. D-Bus系列之获取发送者UID及PID的方法
- Ubuntu Server 14.04下安装桌面环境后出现只有Guest模式的解决方法
- 一名程序员用爬虫技术分析了福州7740家餐厅数据
- Xml HttpClient
- 属性动画