【题解】Crossing River

题目描述

  几个人过河,每次过两人一人回,速度由慢者决定,问过河所需最短时间。

输入格式

  输入t组数据,每组数据第1行输入n,第2行输入n个数,表示每个人过河的时间。

输出格式

  输出t行数据,每行1个数,表示每组过河最少时间。

输入样例

1

4

1 2 5 10

输出样例

17

题解

  容易想到,我们要尽可能利用速度快的人,且尽可能先把慢的人送走。

  据此可以想到贪心策略:设$n$个人的时间升序排列为$a_{1}$到$a_{n}$,那么我们就让第$n$个人把第$1$个人运到对岸,再让第$1$个人自己回来,然后$--n$。

原文地址:https://www.cnblogs.com/kcn999/p/10959338.html

时间: 2024-11-06 09:26:58

【题解】Crossing River的相关文章

poj1700 Crossing River

Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12585 Accepted: 4787 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arrange

POJ 1700 Crossing River(贪心)

V - Crossing River Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1700 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. There

poj 1700 Crossing River

Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12585   Accepted: 4787 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arr

[ACM] poj 1700 Crossing River (经典过河问题)

Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10212   Accepted: 3855 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arr

hihocoder-Week175-Robots Crossing River

hihocoder-Week175-Robots Crossing River Robots Crossing River 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Three kinds of robots want to move from Location A to Location B and then from Location B to Location C by boat. The only one boat between A and B an

POJ1700:Crossing River(过河问题)

POJ1700 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arrangement must

Crossing River POJ过河问题

A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arrangement must be arranged in order to row the boat back and forth so that all people may cross. Each person has

Crossing River

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11814   Accepted: 4476 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arrangement must b

POJ1700 Crossing River(贪心算法训练)

Time Limit: 1000MS          Memory Limit: 10000K          Total Submissions: 13301          Accepted: 5087 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shu