poj1700Crossing River【贪心】
来源:互联网 发布:淘宝的销售金额 编辑:程序博客网 时间:2024/06/05 04:08
Language:
Crossing River
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 12387 Accepted: 4702
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
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int num[1010];int main(){int t,i,j,k,n;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;++i){scanf("%d",&num[i]);}sort(num,num+n);int sum=0;while(n){if(n==1){sum+=num[0];n--;}else if(n==2){sum+=num[1];n-=2;}else if(n==3){sum+=num[0]+num[1]+num[2];n-=3;}else {int time1=num[0]+2*num[1]+num[n-1];int time2=2*num[0]+num[n-1]+num[n-2];sum+=time1>time2?time2:time1;n-=2;}}printf("%d\n",sum);}return 0;}
0 0
- poj1700Crossing River【贪心】
- poj1700Crossing River
- POJ1700Crossing River(过河问题)
- poj1700Crossing River(这过河真经典)
- poj1700 Crossing River 贪心
- 贪心 - poj3258 River Hopscotch
- poj1700--贪心--Crossing River
- River Hopscotch(贪心)
- 贪心 crosing river
- 【贪心】Crossing River
- 【贪心策略】渡河(river)
- ACM 贪心 Crossing River
- POJ - 1700 Crossing River【贪心】
- poj 1700 Crossing River(贪心)
- POJ--1700:Crossing River (贪心)
- poj 1700 Crossing River 【贪心】
- poj 1700 Crossing River 贪心
- Crossing River(贪心+模拟)
- 【OJ二分06】月度开销
- Local declaration of 'XXX' hides instance variable
- Deep learning论文笔记一:ImageNet Classification with Deep Convolutional Neural Networks
- [android] 优化UI卡顿现象
- kettle用xstart打开报错failed to write core dump & the crash happend outside 解决办法
- poj1700Crossing River【贪心】
- iOS开发:获取文件路径总结
- 51nod 1352 集合计数 (扩展欧几里得)
- Web.xm的l配置加载顺序
- Linux 下 socket 高并发分析与优化
- hdoj How many integers can you find 1796 (容斥原理&&DFS)
- anaconda 安装pyspider出错
- 【数据结构和算法】排序算法之二:选择排序和堆排序
- 经典数据交换