题目描述:

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. ]NET Core Lucene.net和PanGu分词实现全文检索

    Lucene.net和PanGu分词实现全文检索 Lucene.net(4.8.0) 学习问题记录五: JIEba分词和Lucene的结合,以及对分词器的思考   前言:目前自己在做使用Lucene. ...

  2. 使用docker save load 的时候的一个小问题

    当你使用docker save image_id > aa.tar ; 然后再使用 docker load < aa.tar 时, 你会发现此时导入的镜像的repository和 tag ...

  3. 物体检测丨从R-CNN到Mask R-CNN

    这篇blog是我刚入目标检测方向,导师发给我的文献导读,深入浅出总结了object detection two-stage流派Faster R-CNN的发展史,读起来非常有趣.我一直想翻译这篇博客,在 ...

  4. 解决Linux下SSH等终端乱码问题

    1.vi /etc/sysconfig/i18n Centos5.5原来内容是: //LANG="en_US.UTF-8" //SYSFONT="latarcyrheb- ...

  5. Android方法数methods超过65536

    当Android App中的方法数超过65535时,如果往下兼容到低版本设备时,就会报编译错误: Cannot fit requested classes in a single dex file. ...

  6. Easyui validatebox后台服务端验证

    Easyui validatebox的验证提示十分好用,可是在实际项目的运用中,经常会遇到需要服务器验证后并返回验证结果信息,比如验证用户名.手机号.邮箱是否已存在.于是就想着怎么拓展Easyui的验 ...

  7. 【虚拟机-网络IP】使用 Powershell 设置 VNET 中的静态 IP

    本文包含以下内容 对已有虚机设置静态 Internal IP 取消对对已有虚机设置的静态 Internal IP 创建静态 Internal IP的虚机 使用中的注意点 请注意:以下操作需要下载最新版 ...

  8. informix服务端卸载后重新安装不成功

    可能原因: 1.实例未删除 2.配置文件未删除 安装成功后远程客户端连接不上问题: 1..如果自己设置的数据库实例报错,换一个数据库实例(database)试试,例如sysadmin

  9. Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  10. 数据库之存储过程-- 基于MySQL

    存储过程基本语法 create procedure procedure_name  [;number] [{@parameter data_type}[varying][=default][outpu ...