【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

秤砣都是在叶子节点。
可以把它看成一个二叉树。
则我们每次只需要选择任意两个"节点",让他们组成一棵二叉树就可以了。
然后虚拟出来一个节点,代表这个子树的根节点。
每次维护一下每个子树的左子树最左端离树的中心距离以及最右端离树的中心的距离即可。
虚拟生成的节点作为一个新的节点动态加入即可。(它的子孙节点们不再可用)
(这样的搜索策略,可以保证所给节点最后都在叶子节点处)
(注意不一定新的虚拟节点的最右端就由右子树得到。因为可能相交,所以也可能是左子树的某个

【代码】

/*
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的更多相关文章

  1. UVa 1354 Mobile Computing[暴力枚举]

    **1354 Mobile Computing** There is a mysterious planet called Yaen, whose space is 2-dimensional. Th ...

  2. 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 ...

  3. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  4. Uva 1354 Mobile Computing

    题目链接 题意: 在一个宽为r 的房间里, 有s个砝码, 每个天平的一端要么挂砝码, 要么挂另一个天平, 并且每个天平要保持平衡. 求使得所有砝码都放在天平上, 且总宽度不超过房间宽度的最大值. 思路 ...

  5. Mobile Computing: the Next Decade论文 cloudlet薄云

    1 Introduction “Information at your fingertips anywhere, anytime” has been the driving vision of mob ...

  6. UVa 1354 天平难题 Mobile Computing

    整个题考虑起来 最主要要计算的状态 是树的状态 于是要计算出所有可能挂坠可能组成的树的所有形态 tree 用于保存这些状态 考虑不要重复计算,有一个vis 数组 预处理可以先计算出一棵树的重量,简化计 ...

  7. UVa 1354 枚举子集 Mobile Computing

    只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...

  8. UVa 1354 天平难题

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. uva 688 - Mobile Phone Coverage

    经典问题,矩形面积并. 解法:一.矩形分割,每个矩形的两个横坐标和两个纵坐标排序,这样得到2n*2n个区间,对这些区间依次判断是否包含在n个矩形中间即可.      二.扫描线.具体还没实现过. 详见 ...

随机推荐

  1. mysql源码安装(包括5.5和5.7)

    1.mysql5.5源码安装 yum install -y cmake ncurses-devel ncurses cd /usr/src wget -c https://cdn.mysql.com/ ...

  2. php,javascript设置和读取cookie

    1.php设置cookie setcookie($name,$value,expire,path,domain,secrue); //$name:指的是cookie的名字:$value指的是cooki ...

  3. 【Uva 10723】Cyborg Genes

    [Link]: [Description] 给你两个串s1,s2; 让你生成一个串S; 使得s1和s2都是S的子列; 要求S最短; 求S的不同方案个数; [Solution] 设两个串的长度分别为n1 ...

  4. 【玲珑杯 round#18 B】图论你先敲完模板

    [Link]:http://www.ifrog.cc/acm/problem/1146 [Description] [Solution] 设f[i]表示在第i个点休息的话最少需要的体力值; f[i]= ...

  5. [Python] Execute a Python Script

    Python scripts can be executed by passing the script name to the python command or created as execut ...

  6. [React] Validate Custom React Component Props with PropTypes

    In this lesson we'll learn about how you can use the prop-types module to validate a custom React co ...

  7. 零基础学python-7.6 字符串格式化表达式

    字符串格式化同意在一个单个的步骤中对一个字符串运行多个特定类型的替换 特别是给用户提示的时候,格式化很方便 实现方法: 1.格式化表达式,类似于c语音的printf 在表达式中,我们使用%二进制操作符 ...

  8. Eclipse怎么导入外来项目

    从File中点击------>import----->General------>然后按下面的图片显示

  9. js--09定时器

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  10. ip---查看网络信息

    Linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者. ifconfig属于net-tools.ip属于iproute2 设置一个IP地址,可以使用下列ip命令: ip add ...