zoukankan      html  css  js  c++  java
  • codeforces #364d As Fast As Possible

    题意:一群学生,要到离这里为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 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 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 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 exceed10 - 6.

    Examples
    input
    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
    ",ans);
        return 0;
    }
    View Code
     
  • 相关阅读:
    初识Python
    MySql的前戏
    abstract class 和 interface 有什么区别?(抽象类和接口的区别)
    java方法签名
    final
    OverLoad 和 Override 的区别
    WebService (什么是WebService ,有哪些优点? WebService由什么组成?分别对应的含义?)
    人民币
    快速排序
    动态反射
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5699455.html
Copyright © 2011-2022 走看看