这道题我怎么看都觉得答案不对
AgroupofNpeoplewishestogoacrossariverwithonlyoneboat,whichcanatmostcarrytwopersons.Th...
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. There won't be more than 1,000,000 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
1
4
1 2 5 10
Sample Output
17
怎么算出17的????
应该回程的时间也算吧,这题已应该是由速度最快的人做船夫运送别人,也就是说过河对岸所要花的时间是除最快速度的和,而回来则是n-2个最快速度的和。用算是来表示就是:
time = 2 + 5 + 10 + 1 * 2 展开
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. There won't be more than 1,000,000 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
1
4
1 2 5 10
Sample Output
17
怎么算出17的????
应该回程的时间也算吧,这题已应该是由速度最快的人做船夫运送别人,也就是说过河对岸所要花的时间是除最快速度的和,而回来则是n-2个最快速度的和。用算是来表示就是:
time = 2 + 5 + 10 + 1 * 2 展开
1个回答
展开全部
有N个人过河,但是只有一条船,一次最多乘2个人,有很多种过河的方案,船必须来回往返。每个人划船的速度都不同,两个人划船的时候,总体速度取决于速度慢的那一个。找出一个N个人全部过河的时间最少的方案。
1代表只有一个事例
4有4个人
1 2 5 10 代表4个过河的时间
算吧,不是17是多少?
你的思维是错的,正确的:
1,2 -> 2 1,2先过,时间是2
2 <- 2 2回去,时间是2
5,10-> 10 5,10过河,时间10
1 <- 1 时间1
1,2 -> 2
总时间17
1代表只有一个事例
4有4个人
1 2 5 10 代表4个过河的时间
算吧,不是17是多少?
你的思维是错的,正确的:
1,2 -> 2 1,2先过,时间是2
2 <- 2 2回去,时间是2
5,10-> 10 5,10过河,时间10
1 <- 1 时间1
1,2 -> 2
总时间17
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |