题目描述

The members of XDU-ACM group went camp this summer holiday. They came across a river one day. There was a ship which only can carry at most two people at the same time. The ship would move only if there is at least one person in the ship to drive it. Everyone had different cost of time to pass the river, and the time of pass the river by ship depended on the longer time of the two passengers. You should tell them the minimum total time that all of the members should spend to arrive the next band.

输入

The input contains multiple test cases.
The first line of each case contains one integer n (1≤n≤100000). Then next n lines contains n positive integers a[i](1≤a[i]≤10000)-the ith person spend a[i] time to pass the river.

输出

For each case ,print the minimum total time they should spend in the only line.

--正文

首先按时间长短排好,则a[1]是最快的,a[2]次快,a[n]最慢,a[n-1]次慢

若 (2*a[2]+a[1]+a[n] > 2*a[1]+a[n-1]+a[n])

  则每次先a[1],a[n]坐船,a[1]回来和a[n-1]坐,a[1]回来

否则就每次a[1],a[2]坐船,a[1]回来,a[n-1]和a[n]坐,a[2]回来

这样每次都少掉2个人,直到n<4为止

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int n;
int a[];
long long res = ; void solve(int n){
if (n <= ){
if (n == ){
res += a[] + a[] + a[];
return;
}
if (n == ){
res += a[];
return;
}
if (n == ){
res += a[];
return;
}
}
res += min(*a[]+a[]+a[n],*a[]+a[n-]+a[n]);
solve(n-);
} int main(){
while (scanf("%d",&n) != EOF){
int i;
res = ;
for (i=;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+,a++n);
// for (i=1;i<=n;i++){
// printf("%d ",a[i]);
// }
solve(n);
printf("%lld\n",res);
}
}

XidianOJ 1176 ship的更多相关文章

  1. BZOJ 1176: [Balkan2007]Mokia

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 2012  Solved: 896[Submit][St ...

  2. 渡轮问题Ship

    题目描述 Palmia河从东往西流过Palmia国,把整个国家分成南北两半.河的两岸各有N个城市,北岸的每一个城市都与南岸的一个城市互为友好城市,而且任意两个北岸城市的友好城市都不相同.每一对友好城市 ...

  3. 【DP】HDU 1176

    HDU 1176 免费馅饼 题意:中文题目不解释. 思路:因为是从中间出发所以思路卡了许久,还在之前做了道HIHO入门的题.能想到的点,从时间思考,然后初始化1s的时候,4,5,6,的数值要特别赋值. ...

  4. A ship is always safe at the shore - but that is not what it is built for.

    A ship is always safe at the shore - but that is not what it is built for. 船靠岸边总是安全的,但那不是建造它的目的.

  5. 【BZOJ 1176】【Balkan 2007】Mokia

    http://www.lydsy.com/JudgeOnline/problem.php?id=1176 整体二分的例题 把每个询问拆成四个询问,整体二分里x坐标递增,按x坐标扫的时候用树状数组维护y ...

  6. Some User Can Not Execute "Ship Confirm"(Doc ID 473312.1)

    APPLIES TO: Oracle Shipping Execution - Version 11.5.10.2 and later Information in this document app ...

  7. HDU 1176免费馅饼 DP数塔问题转化

    L - 免费馅饼 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  8. HDU 1176 免费馅饼(记忆化搜索)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  9. space ship

    按下向上箭头,飞船速度不是一直增加 而且飞船移动的方向是固定的不是有角度的 按下箭头飞船可以飞了,但是不减速 加一个keyup handler就可以啦!可以一直加速,不按的时候也可以减速 按下向下按钮 ...

随机推荐

  1. Oracle数据库初级学习 2

    今天我们介绍Oracle数据库中剩余的查询方法,今天的查询方法会比昨天的更为复杂一些(PS:我也是个初学者,请见谅..). 一.分组函数 分组函数是为了区分同一个表中的不同数据而建立,其关键字为GRO ...

  2. decimalFormat(小数格式)

    这个格式是用来形容小数的,所以只对小数部分起作用 0 一个数字 # 一个数字,不包括 0 (0和#就是一个占位符,有几个就意味着要显示多少位,区别是0 匹配任意数字,#匹配不包括0的任意数字(最后的0 ...

  3. python数据结构与算法——二叉树结构与遍历方法

    先序遍历,中序遍历,后序遍历 ,区别在于三条核心语句的位置 层序遍历  采用队列的遍历操作第一次访问根,在访问根的左孩子,接着访问根的有孩子,然后下一层 自左向右一一访问同层的结点 # 先序遍历 # ...

  4. linux dns 连外网

    以下设置对所用的Linux系统如Redhat/Ubuntu/Debian/CentOS等都有效,但您必须是管理员root或者具有管理员权限 vim /etc/resolv.conf 在其中加入: na ...

  5. poj1458 Common Subsequence ——最长公共子序列

    link:http://poj.org/problem?id=1458 最基础的那种 #include <iostream> #include <cstdio> #includ ...

  6. MySql取得日期(前一天、某一天)

    在测试一个统计表格,发现每次手写一个地址实在很烦,干脆就搞个自动计算好时间区间的东西.以下内容作为收获吧! 取得当天: SELECT curdate(); mysql> SELECT curda ...

  7. 利用freemarker 静态化网页

    1.介绍-FreeMarker是什么 模板引擎:一种基于模板的.用来生成输出文本的通用工具 基于Java的开发包和类库 2.介绍-FreeMarker能做什么 MVC框架中的View层组件 Html页 ...

  8. php接收到的json格式不标准,某个字段中的文本包含双引号的处理

    $str = '[{"Count":"1789"},{"裁判要旨段原文":"本瑶","案件类型":& ...

  9. IE10、IE11解决不能播放Flash的问题!

    http://jingyan.baidu.com/article/154b46315421b528ca8f41e4.html ie的问题向来是windows系统的传统问题之一.几乎每个版本的windo ...

  10. Hadoop学习11--Ha集群配置启动

    理论知识: http://www.tuicool.com/articles/jameeqm 这篇文章讲的非常详细了: http://www.tuicool.com/articles/jameeqm 以 ...