Crossing River
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12260   Accepted: 4641

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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int cmp(int a,int b)
{
return a<b;
}
int main()
{
int t,s[1001];
scanf("%d",&t);
while(t--)
{
memset(s,0,sizeof(s));
int n,sum=0,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n,cmp);
for(i=n-1;i>2;i-=2)
{
if(s[0]*2+s[i]+s[i-1]>s[0]+s[1]*2+s[i])
sum+=s[0]+s[1]*2+s[i];
else sum+=s[0]*2+s[i]+s[i-1];
}
if(i==2) sum+=s[0]+s[1]+s[2];
if(i==1) sum+=s[1];
if(i==0) sum=s[0];
printf("%d\n",sum);
}
return 0;
}

poj1700--贪心--Crossing River的更多相关文章

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

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

  2. 贪心Crossing river

    英文题目: A group of N people wishes to go across a river with only one boat, which can at most carry tw ...

  3. POJ 1700 Crossing River (贪心)

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

  4. poj 1700 Crossing River 过河问题。贪心

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

  5. Crossing River

    Crossing River 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=26251 题意: N个人希望去过 ...

  6. Crossing River(1700poj)

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

  7. poj-1700 crossing river(贪心题)

    题目描述: A group of N people wishes to go across a river with only one boat, which can at most carry tw ...

  8. Crossing River poj1700贪心

    题目描述:N个人过河,只有一只船,最多只能有两人划船,每个人划船速度不同,船速为最慢的人的速度.输入T为case个数,每个case输入N为人数,接下来一行输入的是每个人过河的时间,都不相同.要求输出N ...

  9. 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 ...

随机推荐

  1. android 将手机号中间隐藏为星号(*)

    ){ StringBuilder sb =new StringBuilder(); ; i < pNumber.length(); i++) { char c = pNumber.charAt( ...

  2. 时序分析:DTW算法(基于模板)

    对时序对象进行分析,使用KMP算法可以分析速率不变的模式,参考时序分析:欧式空间轨迹模式识别.使用基于模板匹配的方法,对于速率发生变化的模式,需要用新的对速率要求松散的方法,DTW方法为一种广泛使用的 ...

  3. 【技术累积】【点】【git】【10】.gitignore和.gitattributes

    .gitignore 告诉git忽略一些文件,git status会显示不到这些文件的状态. 一般放在项目根目录,以对全局控制,当然可以放在module下: 具体规则主要是: 以行为单位定义忽略文件类 ...

  4. 团体程序设计天梯赛-练习集-L1-045. 宇宙无敌大招呼

    L1-045. 宇宙无敌大招呼 据说所有程序员学习的第一个程序都是在屏幕上输出一句“Hello World”,跟这个世界打个招呼.作为天梯赛中的程序员,你写的程序得高级一点,要能跟任意指定的星球打招呼 ...

  5. atcoder.keyence2019.contest E-Connecting Cities

    真是道好题啊,当时怎么想都没想出来... 传送门 简述题意: 有n个点,每个点有一个权值Ai,连接i,j两个点的代价是 |i−j|×D+Ai+Aj  其中D是给定的常数,问把n个点联通的最小代价 1≤ ...

  6. C#datetime判断日期输入是否正确

    //7.输入年月日,看看格式是否正确.利用DateTime. //(1) //DateTime dt=DateTime.Now; //Console.Write("请输入现在的年:" ...

  7. [USACO15FEB]Censoring (Silver)

    WA了一万次.... 然后发现多输出了一个空格 我#$%^& 启示我们输出字符的时候应该输出ASCII码看一下.... 然后本题可以用烤馍片算法,每次匹配完以后看看当前最后一位的nxt数组的值 ...

  8. 阿里云 全部端口port

  9. POJ 1703 Find them, Catch them(并查集高级应用)

    手动博客搬家:本文发表于20170805 21:25:49, 原地址https://blog.csdn.net/suncongbo/article/details/76735893 URL: http ...

  10. 使用厂商MIB库查找设备OID值并实施监控的方法

    https://wenku.baidu.com/view/8f4b389e0029bd64783e2cd0.html