poj-3404 Bridge over a rough river Ad Hoc
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
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的更多相关文章
- poj 3404&&poj1700(贪心)
Bridge over a rough river Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4143 Accept ...
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
delphi ado 跨数据库访问 语句如下 ' and db = '帐套1' 报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATE ...
- Ad hoc sql
SQL Server如何启用Ad Hoc Distributed Queries? 2011-08-11 14:53 wangdingbang CSDN博客 字号:T | T 本文主要介绍了SQL ...
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问
消息 15281,级别 16,状态 1,第 2 行SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/Open ...
- XE7 & IOS开发之开发账号(3):证书、AppID、设备、授权profile的申请使用,附Debug真机调试、Ad hoc下iPA文件生成演示(XCode5或以上版本推荐,有图有真相)
网上能找到的关于Delphi XE系列的移动开发的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 注意,以下讨论都是以&q ...
- XE7 & IOS开发之开发账号(2):发布证书、发布授权profile的申请使用,附Ad hoc真机调试、生成ipa文件演示(XCode所有版本通用,有图有真相)
网上能找到的关于Delphi XE系列的移动开发的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 注意,以下讨论都是以&q ...
- 启用与关闭 Ad Hoc Distributed Queries
在数据库里执行以下脚本: 启用: exec sp_configure 'show advanced options',1reconfigureexec sp_configure 'Ad Hoc Dis ...
- Sql导出数据报错-->SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服 ...
- 解除SQL对组件"Ad Hoc Distributed Queries"的"STATEMENT'OpenRowset OpenDatasource"的访问
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为 ...
随机推荐
- error while loading shared libraries
https://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-sh ...
- 编译安装最新版nettle和gnutls
编译安装最新版gnutls的时候,总是会出libnettle 3.4.1 was not found的报错信息. 即使编译安装了nettle的最新版3.5之后,依然会报该错. 原因是gnutls编译的 ...
- idea创建maven的web项目
前言 今天搭xfire的时候,我想对xfire进行一下测试,就想弄个web工程试试,发现网上写的很多没有用的,就自己写了一下.十分精简.也介绍了如何解决maven骨架建立项目非常慢的问题. 介绍 1. ...
- oracle里面查询重复数据的方法
一张person表,有id和name的两个字段,id是唯一的不允许重复,id相同则认为是重复的记录. select id from group by id having count(*) > 1 ...
- 前端之html5和css3
圆角,透明度,rgba CSS3圆角 设置某一个角的圆角,比如设置左上角的圆角:border-top-left-radius:30px 60px;同时分别设置四个角: border-radius:30 ...
- MySQL UNION 查询
UNION 用来合并多个 SELECT 结果. 考察如下两个表: # t1 +----+---------+ | id | pattern | +----+---------+ | 1 | Divot ...
- Koa + GraphQL 示例
初始化项目 创建 graphql-example 文件夹进入后初始化一个 package.json 文件. $ mkdir graphql-example && cd $_ $ yar ...
- django实现客户端文件下载
基于django项目,由于不是专门讲文件的下载,这里仅是项目需要,所以可能不是特别的详细.仅做流程的演示: 实现过程: 1.准备下载url # 下载文件 url(r'^download_file/$' ...
- Thinkphp带表情的评论回复实例
基于Thinkphp开发的一个简单的带表情的评论回复实例,可以无限回复,适合新手学习或作为毕业设计作品等. 评论提交验证 $(".submit-btn").click(functi ...
- C#如何将DataTable中的列名复制到另一个DataTable
C#如何将DataTable中的列名复制到另一个DataTable? 仅复制列名,不复制列下的数据: var newDt = new DataTable(); newDt = oldDataTable ...