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就可以啦!可以一直加速,不按的时候也可以减速 按下向下按钮 ...
随机推荐
- 重新安装配置ubuntu的引导菜单
查看分区挂在情况,找到ubuntu所在分区(boot)$sudo fdisk -l 卸载isodevice镜像设备所在盘分区(boot) $sudo umount -l /isodev ...
- oracle 存储过程的写法
create or replace procedure Getyc is v_id VARCHAR2(36); v_date VARCHAR2(4); begin declare begi ...
- Android Studio Lint 自动检查清除冗余资源
(Android Lint) 辛苦的花了很长的周期 做完了项目. 但是打包完发现 APK 的大小让你瞠目结舌 是不是甚至连自己不知道哪里拷贝过来了代码 和 代码相关的布局文件 资源等, 哪些被使用 哪 ...
- 037. asp.netWeb用户控件之五使用用户控件实现文件上传功能
fileUpload.ascx代码: <%@ Control Language="C#" AutoEventWireup="true" CodeFile= ...
- 正则匹配<{$vcode}>变量
$title="<{t}>您的验证码是:<{/t}><{$vcode}>,<{t}>请在注册页输入验证码并完成注册:验证码<{$vcod ...
- c#检测端口是否被占用
当我们要创建一个Tcp/Ip Server connection ,我们需要一个范围在1000到65535之间的端口 . 但是本机一个端口只能一个程序监听,所以我们进行本地监听的时候需要检测端口是否被 ...
- js计算日期之间的月份差
<script type="text/javascript"> getMonthBetween("2015-05-01","2016-05 ...
- 【学+原】CSS3的2D动画 ——仿NOMOS手表
看CSS3妙味课堂中有一课是介绍如何做钟表界面,然后三根针都能随着时间转动,然后自己在那个简易的版本上做了一些进一部改进. 最关键的知识点应该是transform-origin这个样式,要选对旋转的中 ...
- hpp头文件与h头文件的区别
hpp,其实质就是将.cpp的实现代码混入.h头文件当中,定义与实现都包含在同一文件,则该类的调用者只需要include该hpp文件即可,无需再将cpp加入到project中进行编译.而实现代码将直接 ...
- php数据库访问
从$res获取行数据的时候,处理mysql_fetch_row($res),还有三个方法,分别是 mysql_fetch_row($res); 返回一个所以的数组,速度较快. mysql_fetch_ ...