http://poj.org/problem?id=1700
贪心问题

对于一个安排,怎么样是最小的?首先关于花费,对于每次运输,以最节约的方式运输。两种情况,一种最轻的作为往返,另外 一种是每次带一个,每次带一个。

就要进行选择。到最后特殊判断即可。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,x;
const ll N=1e7+520;
ll a[N],t;
int main()
{
scanf("%lld",&t);
while(t--)
{
x=0;
scanf("%lld",&n);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
sort(a+1,a+1+n);
ll k=1;
while(n>3)
{
x+=min(2*a[1]+a[n-1]+a[n],2*a[2]+a[n]+a[1]);
n-=2;
}
if(n==3)
{
x+=(a[1]+a[2]+a[3]);
}
if(n==2)
{
x+=a[2];
}
if(n==1)
{
x+=a[1];
}
cout<<x<<'\n';
}
return 0;
}

POJCrossing River的更多相关文章

  1. Moon River

    读书笔记系列链接地址http://www.cnblogs.com/shoufengwei/p/5714661.html.        昨晚无意中听到了一首英文歌曲,虽不知其意,但是瞬间就被优美的旋律 ...

  2. poj[3093]Margaritas On River Walk

    Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...

  3. Crossing River

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

  4. BZOJ-1143&&BZOJ-2718 祭祀river&&毕业旅行 最长反链(Floyed传递闭包+二分图匹配)

    蛋蛋安利的双倍经验题 1143: [CTSC2008]祭祀river Time Limit: 10 Sec Memory Limit: 162 MB Submit: 1901 Solved: 951 ...

  5. POJ 3258 River Hopscotch

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11031   Accepted: 4737 ...

  6. River Hopscotch(二分POJ3258)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...

  7. Margaritas on the River Walk_背包

    Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...

  8. POJ 3258 River Hopscotch (binarysearch)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...

  9. POJ 1700 Crossing River (贪心)

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

随机推荐

  1. Python绘制面积图

    一.Python绘制面积图对应代码如下图所示 import matplotlib.pyplot as plt from pylab import mpl mpl.rcParams['font.sans ...

  2. 第46篇-signature_handler与result_handler

    在之前介绍为native方法设置解释执行的入口时介绍过,当Method::native_function为空时会调用InterpreterRuntime::prepare_native_call()函 ...

  3. bjdctf_2020_router

    这道题其实主要考linux下的命令.我们来试一下!!! 可以看到,只要我们在命令之间加上分号,就可以既执行前面的命令,又执行后面的命令... 这道题就不看保护了,直接看一下关键的代码. 这里可以看到s ...

  4. CF1064A Make a triangle! 题解

    Content 有三条长度分别为 \(a,b,c\) 的线段.你可以在一个单位时间内将一条线段的长度增加 \(1\),试求出能使这三条线段组成一个三角形的最短时间. 数据范围:\(1\leqslant ...

  5. CF177A1/A2 Good Matrix Elements 题解

    Content 给定一个 \(n\times n\) 的矩阵,每个元素都有一个值,求出处于两条对角线以及中间行和中间列的元素之和. 数据范围:\(1\leqslant n\leqslant 5(\te ...

  6. jsp部分乱码(并不是没有设置编码的问题)

    当页面跳转的时候,还是有中文的乱码存在,最后发现我没有写页面的提交方式, <form action = "show.jsp"> 用户名:<input type=& ...

  7. 账号不允许远程访问服务器上的mysql数据库的解决办法host is not allowed to connect to this mysql

    改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "use ...

  8. layui(layer)的loading方法显示位置不居中

    要在layer.load之前使用layer.ready方法 layui.use('layer', function () { layer.ready(function(){ index = layer ...

  9. JAVA加解密之DES

    DES加密算法是一种分组密码,以64位为分组对数据加密,它的密钥长度是56位,加密解密用同一算法.DES加密算法是对密钥进行保密,而公开算法,包括加密和解密算法.这样,只有掌握了和发送方相同密钥的人才 ...

  10. 深入理解Akka Actor模型

    Carl Hewitt 在1973年对Actor模型进行了如下定义:"Actor模型是一个把'Actor'作为并发计算的通用原语". Actor是异步驱动,可以并行和分布式部署及运 ...