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

【题意】

在这里输入题意

【题解】

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

【代码】

/*
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. Vue 项目搭建 与 git 连接

    整理一下::::: git 方面: -----------注册------登录--------就不用写了 这里使用的是码云: 1. 进入个人中心添加项目. 2.添加完项目添加SSH公钥.(在设置里面) ...

  2. 昼猫笔记 JavaScript -- 面向对象(I)

    本文内容搬运自公众号 原文链接 本文主要内容:面向对象 预计阅读时间:6分钟 面向对象的方式 单例模式(字面量定义) var obj = {} 类的实例 var obj = new Object() ...

  3. 本地用户 vsftpd 配置文件

    # 禁止匿名用户anonymous登录 anonymous_enable=NO # 允许本地用户登录 local_enable=YES local_root=/data/wwwroot/ # 让登录的 ...

  4. Swift学习笔记(4)--字符串及基本使用

    String是例如“hello, world”,“海贼王” 这样的有序的Character(字符)类型的值的集合,通过String类型来表示. Swift 的String类型与 Foundation  ...

  5. jQuery和JavaScript的点击事件区别

    // $("#indexPage").click(); // 触发了a标签的点击事件,但是没有触发页面跳转 document.getElementById("indexP ...

  6. C# 调用者信息特性(Attribute)

    .NET 4.5中引用了三种特性(Attribute), 该特性允许获取调用者的当前编译器的执行文件名.所在行数与方法或属性名称. 命名空间 System.Runtime.CompilerServic ...

  7. [Python] Python list slice syntax fun

    # Python's list slice syntax can be used without indices # for a few fun and useful things: # You ca ...

  8. Android与webserver数据交互编程---3网络爬虫项目实现虚拟浏览器的jsp后台执行

    背景:原先的b/s设计中在一个jsp界面中实现多个复杂的工作流... 为实现移动接口的调用保证工作流的正常webproject特别给提供了该虚拟浏览器的方案 原理:通过该方案实现虚拟浏览器后台运行js ...

  9. app 设计原则 ,步骤

    原则1:用户没精力研究你的应用.假设一開始不能非常清楚地了解某个应用,不能非常快上手应用.用户就要丢弃这个应用了 原则2:要让用户一眼就知道应用的核心功能和用法 原则3:减少认知负荷,千万不能让客户去 ...

  10. Android 学习笔记之Bitmap位图虽触摸点移动

    package xiaosi.bitmap; import android.app.Activity; import android.os.Bundle; public class mianActiv ...