POJ1700 Crossing River
来源:互联网 发布:cf手游刷枪软件2017 编辑:程序博客网 时间:2024/05/22 14:32
题目:
Crossing River
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 16771 Accepted: 6356
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
代码:
#include<stdio.h>#include<algorithm>using namespace std;int v1[1010];int main(){ int step; scanf("%d",&step); while(step--) { int i,n; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&v1[i]); if(n==1) { printf("%d\n",v1[0]); continue; } sort(v1,v1+n); int compare=v1[0]-2*v1[1],ans=0; for(i=n-1;i>=2;i-=2) { if(i==2) ans+=v1[0]+v1[2]; //剩三人时加上每个人的速度合 else if(compare+v1[i-1]<0) //a+c-2b>0 ans+=(2a+c+d) ans+=2*v1[0]+v1[i-1]+v1[i]; else //a+c-2b<=0 ans+=(a+2b+d) ans+=v1[0]+2*v1[1]+v1[i]; } ans+=v1[1]; printf("%d\n",ans); } return 0;}
阅读全文
0 0
- POJ1700 Crossing River DP
- Crossing River POJ1700
- poj1700 Crossing River 贪心
- POJ1700 Crossing River
- POJ1700:Crossing River
- Crossing River poj1700
- POJ1700 Crossing River
- poj1700--贪心--Crossing River
- poj1700 Crossing River
- POJ1700 Crossing River
- poj1700 Crossing River
- POJ1700 Crossing River
- Crossing River(POJ1700)
- POJ1700 Crossing River
- POJ1700 Crossing River 过河问题
- POJ1700 Crossing River(贪心)
- POJ1700--Crossing River(贪心)
- poj1700 crossing river 贪心(手动翻译)
- 开源 java CMS
- HttpClient方式调用接口的实例
- 塔防篇:Day2
- 【Spring】Spring3.x的下载与配置
- jvm-java中对象的访问
- POJ1700 Crossing River
- Tomcat和Weblogic的区别
- 这些痛,只有程序员懂… | 搞笑动图
- APP UI 真的可以实现自动化测试吗?
- 如何用 Node.js 爬虫?
- 大数据早报:国产新一代人工智能芯片发布 「龙猫数据」获3370万元A轮融资(11.8)
- 通过Ajax post Json类型的数据到Controller
- Error starting a service: StartService: Win32 error 1069:
- 20171107