標籤:
題意:一群學生,要到離這裡為l的地方去。有一輛車,車只有k個座位。人和車的速度分別v1,v2,問你所有人到達的最小時間。
思路:數學題。最小時間就是要求所有同學同時到達。每個同學最多上一次車。那麼顯然總路程就是車走一段,人走一段,且每個同學兩個距離相等。
那麼怎麼求呢?設每個人坐車距離為l1,步行就是l-l1,算一下一共需要車來回接多少次學生,記為cnt。
第一組學生上車地點在0處。然後會坐車往前 走l1,車再回來,去接後面的同學。
設第二組同學上車地點在d處。首先在車走到l1處時,所用的時間為t1=l1/v2。此時第二組和車相差距離d1=l1*(1-v1/v2)。那麼相遇的時間t2=d1/(v1+v2)
那麼第二組同學上車地點d會等於d=(t1+t2)*v1=2*v1*l1/(v1+v2).然後發生什麼呢?車子往前走l1,再回來借第三組學生。
等等?這個過程是不是很眼熟?沒錯,和第一次是一樣的。
所以每次前進的距離也是一樣的。那麼最後一組同學上車的位置也就是2*(cnt-1)*v1*l1/(v1+v2),同時也等於l-l1。
聯立一下求出l1.T=l1/v2+(l-l1)/v2。
一定要注意精度問題!!!! 不是很明白的建議畫個圖一步步推一推。
D. As Fast As Possibletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal tov1. To get to the excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can‘t fit more than k people at the same time) and the speed equal to v2. In order to avoid seasick, each of the pupils want to get into the bus no more than once.
Determine the minimum time required for all n pupils to reach the place of excursion. Consider that the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place immediately and this time can be neglected.
Input
The first line of the input contains five positive integers n, l, v1, v2 and k (1 ≤ n ≤ 10 000,1 ≤ l ≤ 109, 1 ≤ v1 < v2 ≤ 109, 1 ≤ k ≤ n) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.
Output
Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won‘t exceed10 - 6.
Examplesinput
5 10 1 2 5
output
5.0000000000
input
3 6 1 2 1
output
4.7142857143
#include<iostream>#include<stdio.h>using namespace std;int main(){ int n,l,v1,v2,k; scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k); int cnt=n/k; if(n%k) cnt++; double fenzi= (double)l*(v1+v2); double fenmu = (double)(2*v1*(cnt-1)+v1+v2); double l1=fenzi/fenmu; double ans=(l1/v2)+(double(l-l1)/v1); printf("%.12lf\n",ans); return 0;}View Code
codeforces #364d As Fast As Possible