Crossing Bridge

Description

N people wish to cross a bridge at night. It’s so dark around there that they have to cross the bridge under the help of a little lamp. Only one little lamp is available (Oh, Men...) and they have to have the little lamp walking with them. The bridge is of a width such that a maximum of 2 people may cross at a time.

Each person walks at his/her fixed speed. If two people cross the bridge together, they must walk at the pace of the slower one. How fast can you get all N people over the bridge?

Input

The input should be a list of N positive integers, where N is less than or equal to 1,000. And each integer of the list should be less than or equal to 100.

Output

The output should be the minimum time that all the people can cross the bridge.

Sample Input

1 2

Sample Output

2

HINT

Greedy

过桥问题!主要参考:http://blog.csdn.net/morewindows/article/details/7481851

 class Solution {
private:
int _bridge(vector<int> &v, int n) {
if (n == ) return ;
if (n == ) return v[];
if (n == ) return v[];
if (n == ) return v[] + v[] + v[];
int res = ;
int a = v[], b = v[], x = v[n-], y = v[n-];
if ( * b > a + x) res += * a + x + y;
else res += a + * b + y;
return res + _bridge(v, n - );
}
public:
int bridge(vector<int> &v) {
sort(v.begin(), v.end());
return _bridge(v, v.size());
}
};
/**************************************************************
Problem: 45
User: easonliu
Language: C++
Result: Accepted
Time:1 ms
Memory:2708 kb
****************************************************************/

[MeetCoder] Crossing Bridge的更多相关文章

  1. Clock Crossing Adapter传输效率分析 (Latency增加,传输效率降低)

    原创By DeeZeng [ Intel FPGA笔记 ] 在用Nios II测试 DDR3时候发现一个现象 (测试为:写全片,读全片+比对) 用单独的PLL产生时钟(200MHz)驱动 Nios I ...

  2. D - Bridge

    n people wish to cross a bridge at night. A group of at most two people may cross at any time, and e ...

  3. poj-3404 Bridge over a rough river Ad Hoc

    Bridge over a rough river POJ - 3404 Bridge over a rough river Time Limit: 1000MS   Memory Limit: 65 ...

  4. PHP设计模式(八)桥接模式(Bridge For PHP)

    一.概述 桥接模式:将两个原本不相关的类结合在一起,然后利用两个类中的方法和属性,输出一份新的结果. 二.案例 1.模拟毛笔(转) 需求:现在需要准备三种粗细(大中小),并且有五种颜色的比 如果使用蜡 ...

  5. Configure a bridge interface over a VLAN tagged bonded interface

    SOLUTION VERIFIED February 5 2014 KB340153 Environment Red Hat Enterprise Linux 6 (All Versions) Red ...

  6. Create a bridge using a tagged vlan (8021.q) interface

    SOLUTION VERIFIED April 27 2013 KB26727 Environment Red Hat Enterprise Linux 5 Red Hat Enterprise Li ...

  7. Configure bridge on a team interface using NetworkManager in RHEL 7

    SOLUTION IN PROGRESS February 29 2016 KB2181361 environment Red Hat Enterprise Linux 7 Teaming,Bridg ...

  8. 理解 neutron(15):Neutron linux-bridge-agent 创建 linux bridge 的简要过程

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

  9. [LeetCode] Self Crossing 自交

    You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to th ...

随机推荐

  1. Java实战_手把手编写记事本

    Java运用SWT插件编写桌面记事本应用程序 可实现windows系统桌面记事本基本功能.傻瓜式教学,一步一步手把手操作.小白也可自己编写出完整的应用程序. 须要工具:Eclipse(带SWT插件) ...

  2. 高仿美团主界面&lt;一&gt;

    声明:本demo还未完好,正在持续更新中... 先上图吧: 这个小demo资源图片全是用青花瓷抠出来的,如今仅仅是完毕了 一部分. 会持续更行中. . .有兴趣的朋友能够关注我,我们一起coding, ...

  3. ubuntu普通账户获取root权限的方法以及su和su -的区别

    打开命令窗口 输入命令:sudo passwd root 然后按照上图中的操作进行即可. su和su -的命令的不同: su命令和su -命令最大的本质区别就是:前者只是切换了root身份,但Shel ...

  4. 最大整数(Noip1998连接多位数)

    最大整数(Noip1998连接多位数)[问题描述] 设有n个正整数(n≤20),将它们联接成一排,组成一个最大的多位整数. 例如:n=3时,3个整数13,312,343联接成的最大整数为:343312 ...

  5. 转:OGRE场景管理器介绍

    一个场景代表在虚拟世界中显示的物品.场景可以包括静态几何体(比如地形或者室内),模型(比如树.椅子等),光和摄像机.场景有下面种类.室内场景:可能由走廊.有家具的屋子和挂着装饰品的墙组成.室外场景:可 ...

  6. js中setTimeout、setInterval、 clearInterval方法简介

    setTimeout setTimeout(code, millisec) 用于在指定的毫秒数后调用函数或计算表达式. 说明: setTimeout()只执行一次code.如果要多次调用,要使用set ...

  7. 前台导出Word文档思路步骤总结(freemarker)

    1. 需求是导出word带表格,表格列数不变,行数由数据库的值决定: 2. 导出最开始想的是直接前端导出,使用了jquery-wordexport插件,导出后,表格边框全没了,无法使用: 3. 采用了 ...

  8. Nosql数据库的四大分类及分布式数据库CAP原理

    1. Nosql数据库的四大分类 2. 分布式数据库CAP原理 2.1 关系型数据库事务遵循的ACID规则 首先了解传统关系型数据库事务遵循的ACID规则: 原子性(Atomicity):事务里的所有 ...

  9. redis统计大key

    –bigkeys redis-cli -h <host> -p <port> -n <db> --bigkeys 这条命令会从指定的 Redis DB 中持续采样, ...

  10. (原)PyTorch中使用指定的GPU

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6836568.html PyTorch默认使用从0开始的GPU,如果GPU0正在运行程序,需要指定其他G ...