【例题 7-7 UVA - 1354】Mobile Computing
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
秤砣都是在叶子节点。
可以把它看成一个二叉树。
则我们每次只需要选择任意两个"节点",让他们组成一棵二叉树就可以了。
然后虚拟出来一个节点,代表这个子树的根节点。
每次维护一下每个子树的左子树最左端离树的中心距离以及最右端离树的中心的距离即可。
虚拟生成的节点作为一个新的节点动态加入即可。(它的子孙节点们不再可用)
(这样的搜索策略,可以保证所给节点最后都在叶子节点处)
(注意不一定新的虚拟节点的最右端就由右子树得到。因为可能相交,所以也可能是左子树的某个
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
struct node{
double x,y;
int weight;
node(double X,double Y,int Weight){x = X;y = Y;weight = Weight;}
};
vector <node> v;
bool bo[N];
int n;
double r,ans = -1;
void dfs(int dep){
if (dep==n){
double width = v.back().x+v.back().y;
if (width > r) return;
ans = max(ans,width);
return;
}
for (int i = 0;i < (int)v.size();i++)
if (!bo[i]){
for (int j = 0;j < (int) v.size();j++)
if (i!=j && !bo[j]){
bo[i] = bo[j] = true;
double wl = v[i].weight,wr = v[j].weight;
double x,y;
//x*wl == y*wr
//x+y==1
//x = 1-y
//wl-y*wl == y*wr
//y*(wl+wr)==wl
//y = wl/(wl+wr)
y = wl/(wl+wr);
x = 1- y;
v.push_back(node(max(x+v[i].x,v[j].x-y),max(v[j].y+y,v[i].y-x),wl+wr));
dfs(dep+1);
bo[i] = bo[j] = false;
v.pop_back();
}
}
}
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
v.clear();
cin >> r;
cin >> n;
for (int i = 0;i < n;i++){
int x;
cin >> x;
v.push_back(node(0,0,x));
}
memset(bo,0,sizeof bo);
ans = -1;
dfs(1);
if (ans<0){
cout <<"-1"<<endl;
}else{
cout << fixed << setprecision(10) << ans << endl;
}
}
return 0;
}
【例题 7-7 UVA - 1354】Mobile Computing的更多相关文章
- UVa 1354 Mobile Computing[暴力枚举]
**1354 Mobile Computing** There is a mysterious planet called Yaen, whose space is 2-dimensional. Th ...
- UVa 1354 Mobile Computing | GOJ 1320 不加修饰的天平问题 (例题 7-7)
传送门1(UVa): https://uva.onlinejudge.org/external/13/1354.pdf 传送门2(GOJ): http://acm.gdufe.edu.cn/Probl ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- Uva 1354 Mobile Computing
题目链接 题意: 在一个宽为r 的房间里, 有s个砝码, 每个天平的一端要么挂砝码, 要么挂另一个天平, 并且每个天平要保持平衡. 求使得所有砝码都放在天平上, 且总宽度不超过房间宽度的最大值. 思路 ...
- Mobile Computing: the Next Decade论文 cloudlet薄云
1 Introduction “Information at your fingertips anywhere, anytime” has been the driving vision of mob ...
- UVa 1354 天平难题 Mobile Computing
整个题考虑起来 最主要要计算的状态 是树的状态 于是要计算出所有可能挂坠可能组成的树的所有形态 tree 用于保存这些状态 考虑不要重复计算,有一个vis 数组 预处理可以先计算出一棵树的重量,简化计 ...
- UVa 1354 枚举子集 Mobile Computing
只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...
- UVa 1354 天平难题
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 688 - Mobile Phone Coverage
经典问题,矩形面积并. 解法:一.矩形分割,每个矩形的两个横坐标和两个纵坐标排序,这样得到2n*2n个区间,对这些区间依次判断是否包含在n个矩形中间即可. 二.扫描线.具体还没实现过. 详见 ...
随机推荐
- Windows10上使用windbg调试Chromium Windows。
###目的###Windows10上使用windbg调试Chromium Windows. 安装Windows 10 SDK时, 就包含了windbg.exe."C:\Program Fil ...
- Firefox 浏览器有用的插件
1.Undo Closed Tabs Button或Undo Closed Tabs Button (revived) 恢复关闭的标签页 2.NetVideohunter Video Download ...
- 【Redis哨兵集群】
目录 开始配置主从复制 开始配置Redis Sentinel @ *** 在开始之前,我们先来看看Redis的主从复制 主从复制原理: 从服务器向主服务器发送SYNC命令. 主服务器接到SYNC命令后 ...
- SWFupload多图片上传入门教程
本文为转载内容,但所讲内容亲身试验证明可用,转载过来希望能帮助到有需要的人. 转载地址:http://blog.csdn.net/kongjiea/article/details/24290373#c ...
- CCF模拟题 字符串匹配
字符串匹配 时间限制: 1.0s 内存限制: 256.0MB 问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行.你的程序还需支持大小写敏感选项:当选项打开时,表示同一个字母的大写 ...
- 洛谷 P2913 [USACO08OCT]车轮旋转Wheel Rotation
P2913 [USACO08OCT]车轮旋转Wheel Rotation 题目描述 Farmer John has an old-time thresher (wheat harvester) tha ...
- Pku3664
<span style="color:#6600cc;">/* D - Election Time Time Limit:1000MS Memory Limit:655 ...
- 为什么我们须要复杂的password
前两天我打开邮箱一看.收到公司1331一封要求改动邮箱password的邮件. 为什么我们须要一个复杂的password呢?尽管我一直以来设置的password都非常复杂.可是公司这次要求改动pass ...
- Android 採用HTML设计界面
由于Android软件开发分工眼下还没有细化,程序猿往往须要负责软件界面的开发,尽管软件的界面图片已经由美工设计好了.可是假设使用layout技术把软件做成美丽的界面确实非常困难,而是也比較耗时.An ...
- 70.lambda表达式逻辑(二进制转换为为十进制)
#include <iostream> #include <cstring> using namespace std; void main() { auto fun = []( ...