题目描述:

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. selenum autoit上传图片

    目前,一般实现文件图片上传的方式都是有一个按钮,点击之后直接调用操作系统自身的弹框,选择文件后,实现上传.因为Selenium不支持调用操作系统的操作,所以这种情况下,利用Selenium无法完成图片 ...

  2. (转)Linux内核参数设置sysctl命令详解

    Linux内核参数设置sysctl命令详解 原文:https://www.zhukun.net/archives/8064 sysctl是一个允许您改变正在运行中的Linux系统的接口. 它包含一些 ...

  3. 电脑Bois中usb模式启动热键

    组装机主板 品牌笔记本 品牌台式机 主板品牌 启动按键 笔记本品牌 启动按键 台式机品牌 启动按键 华硕主板 F8 联想笔记本 F12 联想台式机 F12 技嘉主板 F12 宏基笔记本 F12 惠普台 ...

  4. 关于验证码在IE中不刷新的快速解决方法

    今天在做验证码的时候发现在IE中,验证码不会刷新,而谷歌等其他浏览器没有问题,所以我想到应该是缓存问题,因为IE默认的设置是如果访问地址没变化就不会去获取而是加载缓存中的内容 所以解决方案就是在验证码 ...

  5. HBase数据模型(1)

    HBase数据模型(1) HBase数据模型(2) 1.0 HBase的特性 Table HBase以表(Table)的方式组织数据,数据存储在表中. Row/Column 行(Row)和列(Colu ...

  6. 常用css和js组件

    1 . input框中插入图标 <div class="col-sm-12 col-xs-12 setLineHeight"> <div class=" ...

  7. MySQL开启skip-name-resolve和skip-networking优化

    使用skip-name-resolve增加远程连接速度 skip-name-resolve 该选项表示禁用DNS解析,属于官方一个系统上的特殊设定不管,链接的的方式是经过hosts或是IP的模式,他都 ...

  8. Exchange DSAccess 事件分析

    本文介绍了如何使用事件 ID 2080 来帮助诊断 Exchange DSAccess 问题中所包含的信息. 许多朋友经常遇到Active Directory 域和Exchange 服务器通信问题.那 ...

  9. POJ Dollar Dayz 美元假日(完全背包,常规+大数)

    题意:给出整数n和k,n代表拥有的钱数量,k代表有k种工具,其价钱分别为1~k.求n元能有多少种购买的方案. 思路:k最大有100,数量过大,要用大数.其他的基本和完全背包一样. #include & ...

  10. JavaScript模板引擎的使用

    为了将数据库中的一组记录转换成HTML输出到界面上,大家都采用哪些做法呢? 在WebForm时代我们经常使用datagrid.repeater,当MVC问世后我们开始直接在视图上编写C#循环语句,而现 ...