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取子串方法slice,substr,substring对比表
在程序语言中,字符串可以说是最常用的一种类型,而在程序中对字符串的操作也是十分频繁.当程序语言自带多种字符串操作的方法时,用该语言编程程序时就有很多的便利性,提高开发的效率.但是当方法过多,甚至目的相 ...
- 动态获取项加入到SQL中去统计
public static List<CustomerAppraisalInfo> ListCustomerAppraisal(int pageIndex, int pageSize, s ...
- 黑马程序员——JAVA基础之File类,递归,打印流,合并切割流
------- android培训.java培训.期待与您交流! ---------- File类 用来将文件或者文件夹封装成对象 方便对文件与文件夹的属性信息进行操作. File对象可以作为参数传递 ...
- Mvc4系列文章
http://www.cnblogs.com/duanshuiliu/tag/MVC/
- python 之post、get与cookie实战
项目名称:登陆考勤管理系统爬取个人考勤信息并写入excel表格 编写目的: 公司经常要统计员工的考勤信息,而员工每次都要登陆考勤系统,再复制相关信息出来,贴到EXCEL,再转给统计人员,统计人员再挨个 ...
- 解决Hibernate向MySQL数据库插入中文乱码问题
有时候我们在用hibernate插入中文的字符会出现乱码情况,如下图所示. 看到这种情况,第一反应便是应用程序用的字符集合数据库用的字符集不统一了.我的数据库用个是mysql的,看一下建表语句.用的是 ...
- 使用Python xlwt写excel文件
如果需要使用Python写Excel文件,首先下载或者安装xlwt. pip install xlwt 下面的这些demo应该可以帮助开发者快速上手使用xlwt写Excel文件: 创建工作簿(work ...
- 今天的工作发现了4年前的“bug一枚”
上午的时候山东公司要求下拨资金160万(因目前系统不能支付个人卡),在下拨单保存的时候系统提示余额不足,我马上看内部存款,结果发现人家还有190万呢,然后就看今天的委托付款单还有下拨单,山东都没有,一 ...
- Eclipse 配置Maven
Eclipse 配置Maven 下载Maven 首先在官网下载Maven:http://maven.apache.org/download.cgi 下载后将其解压到相应的位置 配置Maven环境变量 ...
- 黄聪:WordPress: 使用 wp_insert_attachment 上传附件
我们来研究一下如何在主题或者插件的开发中上传附件: 主要参考这个函数:https://codex.wordpress.org/Function_Reference/wp_insert_attachme ...