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. Android设备广告投放解决方案——大量网络图片、多个网络视频的轮播、缓存与更新

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7742996.html 一:业务场景 基于Android系统的设备上投放广告,诸如:地铁广告屏.自助服务机器上的 ...

  2. PowerDesigner使用笔记

    一:PDM模版使用 1:新建model:File——new model——选择PDM,填上名字.数据库类型 2:右侧工具类使用 3:创建表与配置 点击右侧工具栏中table控件,移动到模版面板内点击一 ...

  3. 为wget命令设置代理

    实验环境:ubuntu 12.04 LTS  goagent 方法一.在环境变量中设置代理 export http_proxy=http://127.0.0.1:8087 方法二.使用配置文件 为wg ...

  4. iOS中TableView小技巧

    摘要: TableView是ios开发中经经常使用到的控件,这里统一记录一下开发中遇到的经常使用小技巧,不断探索更新.也希望大家能够告诉我很多其它经常使用的小技巧啦~一起进步 1.去除多余的列表线条 ...

  5. 【BI】商务智能

    BI的定义 商务智能BI (Business Intellignece) 商务智能是涵盖性术语,包含框架.工具.数据库.分析工具.应用和方法.商务智能的主要目标是实现数据的交互,实现对数据的操作,供管 ...

  6. 文本diff算法Patience Diff

    一般在使用 Myers diff算法及其变体时, 对于下面这种例子工作不是很好, 让变化不易阅读, 并且容易导致合并冲突 void Chunk_copy(Chunk *src, size_t src_ ...

  7. linux c server and client 简单的通信

    server.c #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <st ...

  8. Linux十大常用命令

    No 命令 功能 实例 解释 mkdir 创建目录 mkdir newdirmkdir dir/subdirmkdir -p newdir/subdir -p: 可以是一个路径名称.此时若路径中的某些 ...

  9. http状态--status[查询的资料备注]

    HTTP 状态消息 当浏览器从 web 服务器请求服务时,可能会发生错误. 从而有可能会返回下面的一系列状态消息: 1xx: 信息 消息: 描述: 100 Continue 服务器仅接收到部分请求,但 ...

  10. 树莓派进阶之路 (013) - 树莓派2/3 C语言使用PWM

    我手里面的是树莓派3,系统是Raspbian官方操作系统,已经安装好了wiringPi.        PWM简介:脉宽调制(PWM)是指用微处理器的数字输出来对模拟电路进行控制,是一种对模拟信号电平 ...