Bridge over a rough river

POJ - 3404

Bridge over a rough river
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4427   Accepted: 1824

Description

A group of N travelers (1 ≤ N ≤ 50) has approached an old and shabby bridge and wishes to cross the river as soon as possible. However, there can be no more than two persons on the bridge at a time. Besides it's necessary to light the way with a torch for safe crossing but the group has only one torch.

Each traveler needs ti seconds to cross the river on the bridge; i=1, ... , N (ti are integers from 1 to 100). If two travelers are crossing together their crossing time is the time of the slowest traveler.

The task is to determine minimal crossing time for the whole group.

Input

The input consists of two lines: the first line contains the value of N and the second one contains the values of ti (separated by one or several spaces).

Output

The output contains one line with the result.

Sample Input

4
6 7 6 5

Sample Output

29

Source

Northeastern Europe 2001, Western Subregion
OJ-ID:
poj-3404

author:
Caution_X

date of submission:
20191010

tags:
Ad Hoc

description modelling:
n个人过桥,每个人过桥用时已给出,桥只能承载两个人,过河需要火炬,但是只有一个火炬,问最短过河时间

major steps to solve it:
1.两个人过桥之后需要有人把火炬送回来
2.以未过桥的四个人为一个单位,记为a,b,c,d其中a最快,b次快,c最慢,d次慢,分两种情况,①:每次都由最快的人把火炬送回来②:由最快帮助最慢过河,次快帮助次慢过河,步骤为a,b先过河,然后a回来,c,d一起过河,然后b回来带a过河
两种方式耗时为:①:2a+c+d ②:2b+a+c
3.每次以四人为单位选择过河方式直到剩下的人不足四人为止
warnings:
1.思维误区:容易认为方案一是唯一最有效方案

AC Code:

#include<cstdio>
#include<algorithm>
using namespace std;
int a[];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
}
if(n==) printf("%d\n",a[]);
else {
int ans=;
sort(a+,a+n+);
while(n>) {
if(a[]+a[n-]<*a[]) {
ans+=a[n]+a[]*+a[n-];
}
else {
ans+=a[]+a[]+a[]+a[n];
}
n-=;
}
if(n==) ans+=a[];
else ans+=a[]+a[]+a[];
printf("%d\n",ans);
}
return ;
}

poj-3404 Bridge over a rough river Ad Hoc的更多相关文章

  1. poj 3404&&poj1700(贪心)

    Bridge over a rough river Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4143   Accept ...

  2. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问

    delphi ado 跨数据库访问 语句如下 ' and db = '帐套1' 报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATE ...

  3. Ad hoc sql

    SQL Server如何启用Ad Hoc Distributed Queries? 2011-08-11 14:53 wangdingbang CSDN博客 字号:T | T   本文主要介绍了SQL ...

  4. SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问

    消息 15281,级别 16,状态 1,第 2 行SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/Open ...

  5. XE7 & IOS开发之开发账号(3):证书、AppID、设备、授权profile的申请使用,附Debug真机调试、Ad hoc下iPA文件生成演示(XCode5或以上版本推荐,有图有真相)

    网上能找到的关于Delphi XE系列的移动开发的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 注意,以下讨论都是以&q ...

  6. XE7 & IOS开发之开发账号(2):发布证书、发布授权profile的申请使用,附Ad hoc真机调试、生成ipa文件演示(XCode所有版本通用,有图有真相)

    网上能找到的关于Delphi XE系列的移动开发的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 注意,以下讨论都是以&q ...

  7. 启用与关闭 Ad Hoc Distributed Queries

    在数据库里执行以下脚本: 启用: exec sp_configure 'show advanced options',1reconfigureexec sp_configure 'Ad Hoc Dis ...

  8. Sql导出数据报错-->SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问

    SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服 ...

  9. 解除SQL对组件"Ad Hoc Distributed Queries"的"STATEMENT'OpenRowset OpenDatasource"的访问

      SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为 ...

随机推荐

  1. javaScript之基础介绍

    前言一:javascript历史背景介绍 布兰登 • 艾奇(Brendan Eich,1961年-),1995年在网景公司,发明的JavaScript. 一开始JavaScript叫做LiveScri ...

  2. Spring MVC HTTP406 Not Acceptable

    今天在搞前后端分离用springmvc传递json数据的时候,第一步就卡主了,本着完事开头难的做法(哈哈哈), 报了个406?什么鬼? 百度之后发现很多人也同我一样遇到过这个问题,记录下. 找到的处理 ...

  3. 获取json对象的键数组和值数组

    const obj = {a: 1, b: 2, c: 3}; Object.values(obj);//[1, 2, 3] Object.keys(obj);//["a", &q ...

  4. C#窗体间常用的几种传值方式、以及委托与事件的详细介绍

    窗体间的传值,最好使用委托方式传值,开始之前,我们先来说一下委托与事件的关系. 委托:是一个类. 事件:是委托类型的一个特殊实例,只能在类的内部触发执行. 首先创建2个窗体,这里我们以form1为发送 ...

  5. Fundebug录屏插件更新至0.6.0

    摘要: 录屏插件的性能进一步优化,传输的数据体积大幅度减少. 录屏功能介绍 Fundebug提供专业的异常监控服务,当线上应用出现 BUG 的时候,我们可以第一时间报警,帮助开发者及时发现 BUG,提 ...

  6. LOBs and ORA-01555 troubleshooting (Doc ID 846079.1)

    LOBs and ORA-01555 troubleshooting (Doc ID 846079.1) APPLIES TO: Oracle Database Cloud Schema Servic ...

  7. docker 安装 rabbitMQ服务器

    1. 镜像拉取 拉取rabbitMQ镜像文件,后边要接上 management 表名是拉取带有web管理端的镜像,有web界面方便管理. 2.默认用户运行镜像 docker run -d -p 567 ...

  8. 密度峰值聚类算法(DPC)

    密度峰值聚类算法(DPC) 凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1. 简介 基于密度峰值的聚类算法全称为基于快速搜索和发现密度峰值的聚类算法(cl ...

  9. 初学JavaScript正则表达式(七)

    量词 例: \d{20}\w\d?\w+\d*\d{3}\w{3,5}\d{3,} 20次数字字符 单词字符 出现零次或一次数字字符 至少出现一次单词字符 出现任意次数字字符 出现3次数字字符 出现3 ...

  10. socket 与 websocket的区别

    区别: socket并不是一个协议,而是抽象出来的一层,应用于应用层和传输控制层之间的一组接口, socket是传输控制层协议,websocket是应用层协议 websocket是什么样的协议,具有什 ...