XidianOJ 1176 ship
题目描述
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的更多相关文章
- BZOJ 1176: [Balkan2007]Mokia
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 2012 Solved: 896[Submit][St ...
- 渡轮问题Ship
题目描述 Palmia河从东往西流过Palmia国,把整个国家分成南北两半.河的两岸各有N个城市,北岸的每一个城市都与南岸的一个城市互为友好城市,而且任意两个北岸城市的友好城市都不相同.每一对友好城市 ...
- 【DP】HDU 1176
HDU 1176 免费馅饼 题意:中文题目不解释. 思路:因为是从中间出发所以思路卡了许久,还在之前做了道HIHO入门的题.能想到的点,从时间思考,然后初始化1s的时候,4,5,6,的数值要特别赋值. ...
- 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. 船靠岸边总是安全的,但那不是建造它的目的.
- 【BZOJ 1176】【Balkan 2007】Mokia
http://www.lydsy.com/JudgeOnline/problem.php?id=1176 整体二分的例题 把每个询问拆成四个询问,整体二分里x坐标递增,按x坐标扫的时候用树状数组维护y ...
- 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 ...
- HDU 1176免费馅饼 DP数塔问题转化
L - 免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 1176 免费馅饼(记忆化搜索)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- space ship
按下向上箭头,飞船速度不是一直增加 而且飞船移动的方向是固定的不是有角度的 按下箭头飞船可以飞了,但是不减速 加一个keyup handler就可以啦!可以一直加速,不按的时候也可以减速 按下向下按钮 ...
随机推荐
- iOS- UITextField限制输入长度
限制输入长度的问题,在这里完美的解决了! //先创建一个textField 和 一个button. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
- block捕获自动变量和对象
一.捕获自动变量值 首先看一个经典block面试题: int val = 10; void (^blk)(void) = ^{printf("val=%d\n",val);}; v ...
- Java技术的特点
Java技术是一套完整的IT行业解决方案,其中包含了很多技术.最初是从解决家电设备联网通讯的方案发展起来的,其特点适用于Internet,于是在Internet广泛应用的环境下,迅速发展成为一种计算机 ...
- LintCode Maximum Depth of Binary Tree
1 /** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, ...
- Error:Execution failed for task ':app:transformClassesWithInstantRunForDebug'. > java.lang.ClassNotFoundException: io.realm.RealmObject
这问题错误是在运行时出现的,A-Jiang大神有说明解决方法,大神网址:https://github.com/AndroidJiang/StockChart 如果是as2.0+,可能会出现instan ...
- zoj3551 Bloodsucker ——概率DP
Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4530 A[i]数组表示当吸血鬼有 I 个的时候,还需要的天数.可以 ...
- [转载]BT656/BT601/BT1120协议
[转载] BT656/BT601/BT1120协议以及DM365/DM355/DM6467上使用的YUV颜色空间说明 ITU-R BT.601和ITU-RBT.656国际电信联盟(Interna ...
- maven项目修改java编译版本的方式
背景 使用 maven 3.x 安装到本地后,创建的项目一般都是基于JDK1.5版本.而目前大多数的项目已经升级到1.6或以上,尤其是Servlet3.0 已经要求Java6或以上版本的环境,往往需要 ...
- Composer设置忽略版本匹配的方法
Composer简介 Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们.Composer 不是一个包管理器.是的,它涉及 "pa ...
- redis集群的一些笔记
当节点数量少于6个时候会提示如下信息,初始化一个集群的时候需要6个节点,为什么?? *** ERROR: Invalid configuration for cluster creation. *** ...