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就可以啦!可以一直加速,不按的时候也可以减速 按下向下按钮 ...
随机推荐
- javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")
原因很简单:因为在js中{}表示一个语句块(代码段),所有加上"()"表示表达式
- Zookeeper源码编译为Eclipse工程(转)
原文地址:http://blog.csdn.net/jiyiqinlovexx/article/details/41179293 为了深入学习ZooKeeper源码,首先就想到将其导入到Eclispe ...
- 连HTTPS都有漏洞,这么不安全的互联网我们还要继续用吗?
转载自 http://www.huxiu.com/article/45302/1.html 10月24日和25日,虎嗅君参加了GeekPwn(极棒)安全极客嘉年华活动. 嗯...说是嘉年华,其实就 ...
- c语言scanf返回值
1. scanf 函数是有返回值的,它的返回值可以分成三种情况 1) 正整数,表示正确输入参数的个数.例如执行 scanf("%d %d", &a, &b); 如果 ...
- Linux(Debian)+Apache+Django 配置
配置Apache和Django连接的过程可谓是一波三折,在此记录. 零.基本的安装 软件环境 l Linux-3.2.0-4-amd64-x86_64-with-debian-7.7 l py ...
- loose coupling之函数签名
当函数的参数有多个时(比如多于4个),可以考虑将这些参数组织放入一个class(struct),然后函数参数就减少为一个. 1.以class instance来穿参数,可以很容易在各个函数之间传递参数 ...
- JAVA监听器原理
http://blog.csdn.net/longyulu/article/details/25054697 JAVA监听器原理 标签: 监听器 2014-05-05 15:40 9070人阅读 评论 ...
- vi编辑器的基本使用
进入vi为命令模式,需要按 i/a/o 键进入插入模式(在左下角最后一行有“-- INSERT --”字样). i:光标所在位置,进行输入(相似命令cw) a:光标所在位置的下一个位置,进行输入o ...
- JSP+servlet简单登录实例
一个简单的jsp+servlet实例,实现简单的登录 转载▼ http://blog.sina.com.cn/s/blog_5c5bc9070100z7wb.html 开发环境myeclips ...
- Android 另类方法监听软键盘的弹出收起事件
http://www.cnblogs.com/csonezp/p/5065624.html 最近做的项目碰到个问题,a界面是fragment+recyclerview,b界面带个edittext,并且 ...