题目描述:

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<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std;
#define PI 3.14159265358979323846264338327950 int T,n,a[],t;
int main()
{
scanf("%d",&T);
while(T--)
{
t=;
scanf("%d",&n);
memset(a,,sizeof(a));
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
if(n==)
t=a[];
else if(n==)
t=a[];
else if(n==)
t=a[]+a[]+a[];
else
{
for(int i=n-;i>;i=i-)
{
if(i>=)
{
if(a[]+a[i-]>=*a[])
t=t+a[]+*a[]+a[i];
else
t=t+*a[]+a[i]+a[i-];
}
if(i==)
t=t+a[]+a[]+a[];
if(i==)
t=t+a[]; }
}
printf("%d\n",t);
}
}

poj-1700 crossing river(贪心题)的更多相关文章

  1. POJ 1700 Crossing River (贪心)

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

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

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

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

  4. poj 1700 Crossing River C++/Java

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

  5. POJ 1700 - Crossing River

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

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

                                                                                                       ...

  7. 1700 Crossing River

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

  8. Crossing River(1700poj)

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

  9. POJ 3190 Stall Reservations贪心

    POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...

  10. Sliding Window POJ - 2823 单调队列模板题

    Sliding Window POJ - 2823 单调队列模板题 题意 给出一个数列 并且给出一个数m 问每个连续的m中的最小\最大值是多少,并输出 思路 使用单调队列来写,拿最小值来举例 要求区间 ...

随机推荐

  1. 二开获取yigo设计器里查询集合里中的某个SQL

    package com.bokesoft.lrp_v3.mid.dongming.service; import java.math.BigDecimal; import java.util.Arra ...

  2. D. Blocks 数学题

    Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent bo ...

  3. TDH-ssh免密登录

    [root@tw-node118 ~]# ssh-keygen -t rsa -P '' 这个指令会在/root/.ssh下生成id_rsa和id_rsa.pub文件.看一下/root/.ssh下的文 ...

  4. 关于小米手机USB传输稍大点的文件老中断的问题解决方法!

    关于小米手机USB传输稍大点的文件老中断的问题解决方法! 这是一个很痛苦的事情,当你传输大文件的时候,传输到一半就会莫名其妙的中断,拔插数据线很多次以后,好不容易没准可以成功传输一次. 后来使用了36 ...

  5. java join 方法的使用

    在很多情况下,主线程创建并启动子线程,如果子线程中要进行大量的耗时运算,主线程往往将早于子线程结束之前结束.这时,如果主线程想等待子线程执行完成之后再结束,比如子线程处理一个数据,主线程要取得这个数据 ...

  6. Git中文件属性的变化,被认为是文件有改动

    问题描述: 1.  从公司的git服务器上, 下载最新的代码(zip格式), 解压缩出来, 2.  过一段时间, 去执行git pull代码, 出现如下情况: $ git pull Updating ...

  7. freopen()函数

    freopen函数通过实现标准I/O重定向功能来访问文件,而fopen函数则通过文件I/O来访问文件. freopen函数在算法竞赛中常被使用.在算法竞赛中,参赛者的数据一般需要多次输入,而为避免重复 ...

  8. 一键部署基于SVN开源版本控制系统

    https://market.azure.cn/Vhd/Show?vhdId=11889&version=12961 产品详情 产品介绍Subversion作为新一代的开源版本控制工具,Sub ...

  9. Autoit3脚本编写举例

    以任务管理器为例 1.首先打开任务管理器 2.点击结束任务操作 第一步打开任务管理器 run("C:\WINDOWS\system32\taskmgr.exe"); 第二步点击结束 ...

  10. LeetCode Remove Linked List Elements 删除链表元素

    题意:移除链表中元素值为val的全部元素. 思路:算法复杂度肯定是O(n),那么就在追求更少代码和更少额外操作.我做不出来. /** * Definition for singly-linked li ...