Crossing River
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9887   Accepted: 3737

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 be arranged in order to row the boat back and forth so that all people may cross. Each person has a different rowing speed; the speed of a couple is determined by the speed of the slower one. Your job is to determine a strategy that minimizes the time for these people to get across.

Input

The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. The first line of each case contains N, and the second line contains N integers giving the time for each people to cross the river. Each case is preceded by a blank line. There won't be more than 1000 people and nobody takes more than 100 seconds to cross.

Output

For each test case, print a line containing the total number of seconds required for all the N people to cross the river.

Sample Input

1
4
1 2 5 10

Sample Output

17

Source

 
每一趟的决策判断。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std; int f[];
bool cmp(int n1,int n2)
{
return n1>n2;
}
int main()
{
int T;
int i,k,n,Sum,Min;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",&f[i]);
sort(f+,f++n,cmp);
if(n== || n==)
{
printf("%d\n",f[]);
continue;
}
if(n==)
{
printf("%d\n",f[]+f[]+f[]);
continue;
}
int min1=f[n];
int min2=f[n-];
if(n&) k=n-;
else k=n-;
for(i=,Sum=;i<=k;i=i+)
{
Min=min(min2+min1+f[i]+min2,f[i]+min1+f[i+]+min1);
Sum=Sum+Min;
}
if(n&) Sum=Sum+f[n-]+min1+min2;
else Sum=Sum+min2; printf("%d\n",Sum);
}
return ;
}

poj 1700 Crossing River 过河问题。贪心的更多相关文章

  1. POJ 1700 Crossing River (贪心)

    Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9585 Accepted: 3622 Descri ...

  2. ACM学习历程——POJ 1700 Crossing River(贪心)

    Description A group of N people wishes to go across a river with only one boat, which can at most ca ...

  3. poj 1700 Crossing River C++/Java

    http://poj.org/problem?id=1700 题目大意: 有n个人要过坐船过河,每一个人划船有个时间a[i],每次最多两个人坐一条船过河.且过河时间为两个人中速度慢的,求n个人过河的最 ...

  4. POJ 1700 - Crossing River

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13982   Accepted: 5349 Description A gr ...

  5. POJ 1700 cross river (数学模拟)

                                                                                                       ...

  6. POJ1700:Crossing River(过河问题)

    POJ1700 题目链接:http://poj.org/problem?id=1700 Time Limit:1000MS     Memory Limit:10000KB     64bit IO ...

  7. 1700 Crossing River

    题目链接: http://poj.org/problem?id=1700 1. 当1个人时: 直接过河 t[0]. 2. 当2个人时: 时间为较慢的那个 t[1]. 3. 当3个人时: 时间为 t[0 ...

  8. POJ 1700 经典过河问题(贪心)

    POJ题目链接:http://poj.org/problem?id=1700 N个人过河,船每次最多只能坐两个人,船载每个人过河的所需时间不同,问最快的过河时间. 思路: 当n=1,2,3时所需要的最 ...

  9. Crossing River(1700poj)

    Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9919   Accepted: 3752 De ...

随机推荐

  1. HDU6184【Counting Stars】(三元环计数)

    题面 传送门 给出一张无向图,求 \(4\) 个点构成两个有公共边的三元环的方案数. 题解 orz余奶奶,orz zzk 首先,如果我们知道经过每条边的三元环个数\(cnt_i\),那么答案就是\(\ ...

  2. Logstash IIS日志采集

    Logstash IIS 日志采集,跟Linux上运行差不多,都需要java运行环境,装个jdk就好了,对于IIS日志暂时未处理X-forward-for,纠结怎么弄当中,貌似要装个插件,慢慢研究. ...

  3. [Swift实际操作]八、实用进阶-(8)使用performSegue在故事板页面之间进行数据传递

    本文将演示故事板页面之间的数据传递.首先在一个空白项目中,打开项目自带的故事板文件(Main.storyboard).故事板中已经拥有了一个视图控制器,点击选择该视图控制器.然后依此点击[Editor ...

  4. Postman使用手册2——管理收藏

    一.开始使用收藏夹 收藏夹会使你的工作效率更上一层楼 收藏夹可以让单个的request分组在一起,这些request可以被进一步的管理到文件夹来更准确的反应你的API.request也可以在保存到收藏 ...

  5. C#找出接口的所有实现类并遍历执行这些类的公共方法

    //这里找出了实现IOutputArray接口的所有类 private void FindAllClass() { var types = AppDomain.CurrentDomain.GetAss ...

  6. js-查找字符串中出现次数最多的字符

    假设有一个字符串,下面让我们一起来查找出现次数最多的字符 var str = 'asdfssaaasasasasaa'; 首先,我们定义一个Object用来存放拆分的字符串,然后遍历字符串. 判断ob ...

  7. [原创]markdown语法学习(commonmark)

    CommonMark是markdown的解析器,以下是部分学习链接: commonmark规范 https://spec.commonmark.org/ commonmark帮助 https://co ...

  8. 128th LeetCode Weekly Contest Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  9. Django之ContentTypes

    ContentTypes是什么? ContentTypes是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中. 每当我们创建了新的mode ...

  10. odoo 的字段。orm对象

    OpenERP ORM 对象方法列表   OpenERP对象支持的字段类型有,基础类型:char, text, boolean, integer, float, date, time, datetim ...