【例题 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个矩形中间即可. 二.扫描线.具体还没实现过. 详见 ...
随机推荐
- Python正则表达式初识(二)
前几天给大家分享了Python正则表达式初识(一),介绍了正则表达式中的三个特殊字符“^”.“.”和“*”,感兴趣的伙伴可以戳进去看看,今天小编继续给大家分享Python正则表达式相关特殊字符知识点. ...
- 实例讲解Nginx下的rewrite规则 来源:Linux社区
一.正则表达式匹配,其中:* ~ 为区分大小写匹配* ~* 为不区分大小写匹配* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配二.文件及目录匹配,其中:* -f和!-f用来判断是否存在文件* ...
- CSUOJ 1551 Longest Increasing Subsequence Again
1551: Longest Increasing Subsequence Again Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 75 Solved ...
- 利用"SQL"语句自动生成序号的两种方式
1.首先,我们来介绍第一种方式: ◆查询的SQL语句如下: select row_number() over (order by name) as rowid, sysobjects.[name] f ...
- 自己写unicode转换ascii码,wchar*到char*
对于ascii码的char事实上就是unicode码wchar的首个字节码, 如wchar[20] = "qqqq"; 在内存中排码事实上是char的'q' '\0'这类.因此我们 ...
- log大全
http://www.iconfont.cn/search/index?q=%E6%88%91%E7%9A%84&page=3
- BZOJ3994: [SDOI2015]约数个数和(莫比乌斯反演)
Description 设d(x)为x的约数个数,给定N.M,求 Input 输入文件包含多组测试数据. 第一行,一个整数T,表示测试数据的组数. 接下来的T行,每行两个整数N.M. Out ...
- chage---修改帐号和密码的有效期限
chage命令 chage命令是用来修改帐号和密码的有效期限. 语法 chage [选项] 用户名 选项 -m:密码可更改的最小天数.为零时代表任何时候都可以更改密码. -M:密码保持有效的最大天 ...
- 结构体类型重声明导致的bug一个
bug前提条件 当模块比較多.头文件较多,某个结构体类型会在当前模块中又一次声明进而引用其成员,而不直接包括其它模块的头文件. 这种优点是不引入不须要的类型声明到此模块.头文件包括的交叉:坏处是,添加 ...
- Codeforces Round #316 (Div. 2) A B C
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...