[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 ...
随机推荐
- Influxdb数据存储
环境: CentOS6.5_x64 InfluxDB版本:1.1.0 InfluxDB存储引擎看起来很像一个LSM Tree,它包含预写日志和类似存储在LSM Tree中的SSTables只读数据. ...
- SpringMVC学习笔记六:使用 hibernate-validator注解式数据校验
对客户端传过来的参数,在使用前一般需要进行校验. SpringMVC框架内置了Validator验证接口,但是实现起来太麻烦.我们一般使用 hibernate-validator进行数据校验. 1:j ...
- linux下切换python2和python3(转)
0x00 为什么需要有两个版本的Python Python2和Python3不兼容是每个接触过Python的开发者都知道的事,虽说Python3是未来,但是仍然有很多项目采用Python2开发.Lin ...
- oracle-sakila-db sakila的Oracle版本
在Sakila——MySQL样例数据库解析 中,学习了sakila for mysql的表结构.并把它作为数据仓库.ODI ETL学习的源数据库.ODI Studio拓扑结构的创建与配置 后来发现OD ...
- java 生成GUID与UUID
java 生成GUID与UUID CreateTime--2018年5月31日16点29分 Author:Marydon import java.util.UUID; public static ...
- 〖Network〗宿舍配置两路由器,同时访问校园内网和校园外网
环境: 校园宿舍, 10.x.x.x 和 172.16.x.x~172.31.x.x是校园内网,本科教务系统什么的都在上边 路由器: 路由器1(校园内网):水星MR807 路由器2(拨号上网):TP ...
- eclipse与SVN 结合(删除SVN中已经上传的问题)
问题是: 我有一个文件已经上传到了SVN ,但是我想把这个在SVN上的目录删除掉? 解决方法如下: 1,第一步,先在本地删除所有的你需要删除的文件: 2,第二步,选择当前的项目右键“Team”—“Up ...
- WIN10-修改网卡MAC
在注册表位置: 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002 ...
- 【CAS单点登录视频教程】 第03集 -- 配置 tomcat的 ssl
目录 ----------------------------------------- [CAS单点登录视频教程] 第06集[完] -- Cas认证 学习 票据认证FormsAuthenticati ...
- Safari导入书签
1.打开Safari 这边safari会自动带出一些关联的浏览器,但如果你要导入的浏览器不在这里的话,就需要看第二步. 2.比如,这里我要从QQ浏览器导入,先打开QQ浏览器. 其他浏览器都类似,找到书 ...