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. Ubuntu安装CUDA、CUDNN比较有用的网址总结

    Ubuntu安装CUDA.CUDNN比较有用的网址总结 1.tensorflow各个版本所对应的的系统要求和CUDA\CUDNN适配版本 https://tensorflow.google.cn/in ...

  2. KeContextToKframes函数逆向

    在逆向_KiRaiseException(之后紧接着就是派发KiDispatchException)函数时,遇到一个 KeContextToKframes 函数,表面意思将CONTEXT转换为 TRA ...

  3. vs2017 发布工具 Installer 发包遇到的问题处理

    一. 遇到的问题. ERROR: 要在“系统必备”对话框中启用“从与我的应用程序相同的位置下载系统必备组件”,必须将“Microsoft .NET Framework 4.7.2 (x86 和 x64 ...

  4. Java入门——编写并运行第一个程序

    Java入门——编写并运行第一个程序 摘要:本文主要介绍如何使用Java语言编写并通过DOS运行简单的程序. 编写简单的程序 在D盘新建一个文本文档,输入如下代码: class Hello { pub ...

  5. 用vue和layui简单写一个响应式数据展示表

    在创建项目之前,先把我们需要的文件打包处理 <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  6. CSS边框使用-基础

    前端开发工作中经常会碰到奇形怪状的图形,当然也少不了UI设计童鞋的脑洞和创意啦,初级的开发人员可能会选择使用图片做背景加上位置属性实现,不过很多时候,CSS能实现的就不要再动用PS等工具了,时间宝贵, ...

  7. Discuz 数据库各表的作用

    pre_common_addon 插件扩展中心服务商表 pre_common_admincp_cmenu 后台管理面板,自定义常用菜单表 pre_common_admincp_group 后台团队职务 ...

  8. 版本管理·玩转git(远程仓库配置和配置公钥免密登录)

    git系列的最后一部分内容,我们先来看看如何查看远程仓库. 输入 git remote -v 我们还可以删除远程库,输入 git remote remove origin 删除后再次查询,信息为空. ...

  9. [20190531]ORA-600 kokasgi1故障模拟与恢复(后续).txt

    [20190531]ORA-600 kokasgi1故障模拟与恢复(后续).txt --//http://blog.itpub.net/267265/viewspace-2646340/=>[2 ...

  10. centos安装php5、卸载php、安装php7

    这篇文章主要介绍了centos安装php5.卸载php.安装php7 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 首先安装php5很简单 yum install php 然后如果不 ...