题目链接

题意:

  在一个宽为r 的房间里, 有s个砝码, 每个天平的一端要么挂砝码, 要么挂另一个天平, 并且每个天平要保持平衡。

  求使得所有砝码都放在天平上, 且总宽度不超过房间宽度的最大值。

思路:

  每个节点只能有两个子节点, 这是一棵二叉树的形式。

  通过枚举二叉树的形态, 再枚举每一个叶子节点所放砝码, 最后再计算每个方案的宽度并计算答案。

  每增加一个天平, 那么可以放砝码数 + 1。

note:

  坑在0的输出了, 用primtf("%.9lf\n", 0)输出来的是0  用0.0来输出才是0.000000 惨wa三发。

代码:

  

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-5
#define MAXN 110
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {cout<<x<<endl;}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int n;
double r, ans;
double w[MAXN], v[MAXN];
double ll[MAXN], rr[MAXN];
bool vis[MAXN];
int order[MAXN];
void read()
{
scanf("%lf", &r);
scanf("%d", &n);
for (int i = ; i <= n; i ++)
scanf("%lf", &w[i]);
}
void get_ans(int u)
{
memset(ll, , sizeof(ll));
memset(rr, , sizeof(rr));
memset(v, , sizeof(v)); for (int i = u; i > ; i --)
{
if (order[i] == -)
{
int x = i * ;
int y = i * + ;
v[i] = v[x] + v[y];
double li = v[y] / v[i];
double ri = v[x] / v[i]; ll[i] = min(-li + ll[x], ri + ll[y]);
rr[i] = max(-li + rr[x], ri + rr[y]);
}
else if (order[i])
{
v[i] = w[order[i]];
}
} double temp = rr[] - ll[];
//printf("%.9lf\n", temp);
if (temp - r < eps && temp > ans)
ans = temp;
} void dfs(int u, int num, int count)
{
//printf("%d %d %d\n", u, num, count);
if (count == )
{
get_ans(u - );
return ;
}
else if (order[u / ] != -)
{
dfs(u + , num, count);
}
else
{
if (count > num)
{
order[u] = -;
dfs(u + , num + , count);
order[u] = ;
} if (num == && count > )
return ;
for (int i = ; i <= n; i ++)
if (!vis[i])
{
vis[i] = true;
order[u] = i;
dfs(u + , num - , count - );
order[u] = ;
vis[i] = false;
}
}
}
void solve()
{
memset(vis, false, sizeof(vis));
memset(order, , sizeof(order));
ans = -;
if (n == ) printf("%.10lf\n", 0.0);
else
{
order[] = -;
dfs(, , n);
printf(ans == -? "-1\n" : "%.10lf\n", ans);
}
} int main()
{
int T;
scanf("%d", &T);
while (T --)
{
read();
solve();
}
return ;
}

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. Mobile Computing: the Next Decade论文 cloudlet薄云

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

  5. UVa 1354 天平难题 Mobile Computing

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

  6. UVa 1354 枚举子集 Mobile Computing

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

  7. 【例题 7-7 UVA - 1354】Mobile Computing

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 秤砣都是在叶子节点. 可以把它看成一个二叉树. 则我们每次只需要选择任意两个"节点",让他们组成一棵二叉树就可以 ...

  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. google perftools分析程序性能

    Google perftools 1.功能简介 它的主要功能就是通过采样的方式,给程序中cpu的使用情况进行“画像”,通过它所输出的结果,我们可以对程序中各个函数(得到函数之间的调用关系)耗时情况一目 ...

  2. oepn sync

    http://blog.csdn.net/cywosp/article/details/8767327 SYNOPSIS #include <sys/types.h> #include & ...

  3. HD1285(拓扑排序)

    package cn.hncu.dataStruct.search.topSort; import java.util.Scanner; public class Hdu1285 { static S ...

  4. Debian 6解决中文乱码

    DEBIAN下中文显示 一.首先检查LOCALE情况 说明:DEBIAN因为基于GNU所以,对不同地域进行了不同的包支持,以LOCALE形式存在. 1.挂载ISO文件包,前8个ISO包就可以(这里不在 ...

  5. Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project '项目名'

    问题描述: Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project 'myf'. ...

  6. nofollow标签如何使用

    “nofollow”的意思是不传递权重,向网站站长提供了一种方式,即告诉搜索引擎“不要追踪此网页上的链接”或“不要追踪此特定链接”. nofllow的形式 1.<meta name=" ...

  7. webform 转 MVC 飞一般的感觉

    前言: 浅谈webform与mvc,让开发变得更加简单,这里主要通过比较webform与mvc的开发方式,以下全属个人看法,不完善的地方可以留言补充. 正文: 废话不多说,直接说工作中经常用到的地方 ...

  8. poj1308 Is It A Tree?(并查集)详解

    poj1308   http://poj.org/problem?id=1308 题目大意:输入若干组测试数据,输入 (-1 -1) 时输入结束.每组测试数据以输入(0 0)为结束标志.然后根据所给的 ...

  9. MyBatis3.1 学习教程

    昨天中午,突然有想要学习 MyBatis 的冲动,经过 1.5 天的研究和学习,再加上以前学过 I batis 的经验,很快就了解了这门技术. 写这篇教程,是想告诉那些想学却又怕学习不好的同学们, 其 ...

  10. C# 简单的图像边缘提取

    博主做的很简单,大家看一看就好了...... 用到的算法是robert算子,这是一种比较简单的算法: f(x,y)=sqrt((g(x,y)-g(x+1,y+1))^2+(g(x+1,y)-g(x,y ...