[MeetCoder] Crossing Bridge
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的更多相关文章
- Clock Crossing Adapter传输效率分析 (Latency增加,传输效率降低)
原创By DeeZeng [ Intel FPGA笔记 ] 在用Nios II测试 DDR3时候发现一个现象 (测试为:写全片,读全片+比对) 用单独的PLL产生时钟(200MHz)驱动 Nios I ...
- 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 ...
- 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 ...
- PHP设计模式(八)桥接模式(Bridge For PHP)
一.概述 桥接模式:将两个原本不相关的类结合在一起,然后利用两个类中的方法和属性,输出一份新的结果. 二.案例 1.模拟毛笔(转) 需求:现在需要准备三种粗细(大中小),并且有五种颜色的比 如果使用蜡 ...
- 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 ...
- 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 ...
- 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 ...
- 理解 neutron(15):Neutron linux-bridge-agent 创建 linux bridge 的简要过程
学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...
- [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 ...
随机推荐
- Flash Actionscript AS3 渐变透明 mask遮罩
把图片变成渐变透明(左图是效果图,右图是原图) var a:Sprite = new Sprite(); a.graphics.beginGradientFill(GradientType.LI ...
- java 判断字符串中是否包含中文并过滤掉中文
java判断字符串中是否包含中文并过滤掉中文 CreateTime--2017年9月6日08:48:59 Author:Marydon 1.判断字符串中是否包含中文方法封装 /** * 判断字符串 ...
- 〖Linux〗Kubuntu设置打开应用时就只在打开时的工作区显示
有没有遇到一种情况: 在工作区1打开了应用程序Google Chrome: 这个时间感觉它打开速度比较慢,就快捷键切换到工作区2了: 结果这个时候,Google Chrome就直接在工作区2打开,多不 ...
- C# 代码实现设置用户"NETWORK SERVICE"具有对文件夹的读取权限。
设置用户"NETWORK SERVICE"具有对文件夹的读取权限. 原帖地址: http://www.cnblogs.com/sjhrun2001/archive/2009/03/ ...
- mysql查询高级用法
联合查询 select a.* , b.adress , b.name from a , b where a.sbNo = b.cdid order by a.sbNo , a.STime selec ...
- Linux下RocksDB、LevelDB、ForestDB性能测试对比
简要说明 本次环境与http://www.cnblogs.com/oloroso/p/6306352.html中的一致. 依然是增删查改各测试10000次,每个测试重复5次取平均值. 1.不使用jem ...
- vmware中的 CentOS7 虚机磁盘动态扩容
0.在vmware的配置项中,将虚机的磁盘大小调大,步骤简单,此处略 查看当前状态 文件系统状态 df -h 磁盘状态 lsblkfdisk -l 1.首先要再创建一个物理分区 (使用fdisk ...
- 不同类型的磁盘存储在Ubuntu下的性能测试
Ubuntu下通过lsusb判断USB存储是否是USB3.0: # 要查看Seagate这个移动硬盘 lsusb 或者 lsusb -t $ lsusb Bus Device : ID : Intel ...
- 你想知道的关于JavaScript作用域的一切(译)
原文链接: Everything you wanted to know about JavaScript scope 原文作者: Todd Motto JavaScript中有许多章节是关于scope ...
- Docker命令分类及使用场景分布(脑图)
常见的Docker命令分类主要有 不同使用场景下的命令分布 有疑问可到官方文档查询: https://docs.docker.com/engine/reference/commandline/dock ...