zoukankan      html  css  js  c++  java
  • Codeforces Round #364 (Div. 2)D. As Fast As Possible

    D. As Fast As Possible

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard 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 to v1. 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 nlv1, 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 exceed 10 - 6.

    Examples
    input
    5 10 1 2 5
    output
    5.0000000000
    input
    3 6 1 2 1
    output
    4.7142857143
    Note

    In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.

    为了使时间最短,肯定是同时出发,同时到达。然后,然后就不会做了。QAQ

    看了这位菊苣的解释,清晰了。链接:http://blog.csdn.net/acm_fighting/article/details/52003538

    思路:要使最快的话,那么每个人达到终点的时间应该都是相同的,所以每个人乘车的路程也是相同的

    设times=n/k+(n%k == 0 ? 0:1),a为每个人乘车的路程

    除了最后一次载客之外,另外每次载客都还需要回来载下一批,t为来回的时间,x为下一次载的人当前的位置

    那么x+t*v1表示经过t时间后下一次载的人的位置,(t-a/v2)*v2表示汽车走了a之后返回走的路程

    所以x+t*v1=a+x-(t-a/v2)*v2,(画图一下就看出)

    那么t=2*a/(v1+v2)

    而且人到终点的总时间和车到终点的总时间是相同的,即t*(times-1)+a/v2=a/v2+(l-a)/v1

    解出a=(v1+v2)*l/(v1+v2+2*(times-1)*v1)。

    答案为a/v2+(l-a)/v1.

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <map>
     6 using namespace std;
     7 typedef long long ll;
     8 int main()
     9 {
    10    double l,v1,v2,times,t,a;
    11    int n,k;
    12    cin>>n>>l>>v1>>v2>>k;
    13    times = n/k+(n%k==0?0:1);
    14    a = (v1+v2)*l/(v1+v2+2*(times-1)*v1);
    15    t = (l-a)/v1+a/v2;
    16    printf("%lf
    ",t);
    17     return 0;
    18 }
  • 相关阅读:
    移动端line-height问题
    Android8 自定义广播接收不到的问题
    vue 使用font-awesome
    在vue中使用highcharts的仪表图等扩展
    android控件RecyclerView中,如何显示自定义分割线以及最后一项去除分割线
    使用RecyclerView设置自定义分割线
    Android-配置文件中设置“android:clickable="false"无效的原因及解决办法
    HDU 4632 Palindrome subsequence (区间DP)
    HDU 2208 唉,可爱的小朋友(DFS)
    HDU 4618 Palindrome Sub-Array
  • 原文地址:https://www.cnblogs.com/littlepear/p/5815940.html
Copyright © 2011-2022 走看看