POJ 1700 Crossing River
来源:互联网 发布:淘宝怎么删除我的订单 编辑:程序博客网 时间:2024/05/02 17:32
Crossing River
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 10203 Accepted: 3852
Description
A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arrangement must be arranged in order to row the boat back and forth so that all people may cross. Each person has a different rowing speed; the speed of a couple is determined by the speed of the slower one. Your job is to determine a strategy that minimizes the time for these people to get across.
Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. The first line of each case contains N, and the second line contains N integers giving the time for each people to cross the river. Each case is preceded by a blank line. There won't be more than 1000 people and nobody takes more than 100 seconds to cross.
Output
For each test case, print a line containing the total number of seconds required for all the N people to cross the river.
Sample Input
141 2 5 10
Sample Output
17
Source
POJ Monthly--2004.07.18
#include<stdio.h> #include<algorithm>using namespace std;int main(){int t,n,a[1001];scanf("%d",&t);while(t--){scanf("%d",&n);int i,j,k;for(i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);if(n==1)k=a[0];else {k=a[1];for(j=n-1;j>2;j=j-2){if(a[1]*2-a[0]-a[j-1]<0)k=k+a[j]+a[0]+a[1]*2;elsek=k+a[0]*2+a[j]+a[j-1];}if(n%2)k=k+a[0]+a[2];}printf("%d\n",k);}}
0 0
- poj 1700 Crossing River
- Poj 1700 Crossing River
- POJ 1700 Crossing River
- [poj] 1700 Crossing River
- POJ 1700 Crossing River
- poj 1700 Crossing River
- POJ-1700-Crossing River
- poj-1700 Crossing River
- POJ 1700 Crossing River
- POJ 1700 Crossing River
- poj 1700 Crossing River
- poj 1700 Crossing River
- POJ 1700 Crossing River
- poj 1700 Crossing River
- POJ 1700:Crossing River
- poj 1700 Crossing River
- POJ 1700 Crossing River
- POJ 1700 Crossing River
- android 联系人存储结构
- 删除oracle重复数据记录
- Shell脚本之sed篇
- ECSHOP修改模板知识大全
- Canonical Correlation Analysis(一)
- POJ 1700 Crossing River
- 去掉UIWebView上下滚动出边界时的黑色阴影
- 2014年腾讯实习生招聘最后一题
- Java学习系列(一)Java的运行机制、JDK的安装配置及常用命令详解
- Apache POI组件操作Excel(导入和导出)
- 程序的内存分配
- sizeof(结构体)和内存对齐以及位域
- Howto let the SAX parser determine the encoding from the xml declaration?
- 自然语言处理(NLP)网上资源整理