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\n",ans);
    return 0;
}

时间: 2024-07-30 13:43:51

codeforces #364d As Fast As Possible的相关文章

Codeforces 700A As Fast As Possible(二分答案)

[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离,每个人只能上车一次,车可以来回走,问所有人到达目的地所需要的最短时间是多少 [题解] 因为车可以载k个人,所以,我们把人k个为一组分成(n+k-1)/k组,记为p吗,设需要的最短时间为t,每个人在车上待的时间为t2,那么可以列方程v1*(t-t2)+v2*t2=l,我们可以发现t2可以用t来表示,

CodeForces 700A As Fast As Possible

要保证总时间最短,因为总时间计的是最后一个人到达的时间,也就是最后一个人要求尽快到达,也就是说我们要让最后一个人乘车时间尽量多.再仔细想想可以发现每个人的乘车时间和走路时间都是一样的. 因此,可以二分每个人的乘车时间$m$,然后进行验证,如果发现某一个人的乘车时间不到$m$,那么$m$不可取,上界缩小:如果$m$可取,那么上界增大. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio>

codeforces 700a//As Fast As Possible// Codeforces Round #364(Div. 1)

题意:n个人要运动ll长,有个bus带其中几个人,问最短时间 最后所有人在同一时间到终点是用时最少的.由于搭bus相当于加速,每个人的加速时间应该一样.先计算bus走过的路程route.看第一个人被搭t分钟(也就是所有人以后都搭t分钟),剩余的人走t分钟,route+=v2*t.bus到了v2*t的位置,人在v1*t的位置.bus回去接人,被接的人继续前进.route2=(v2*t-v1*t)/(v1+v2)*v2(相向而行).接到人后再走v2*t,结果就是这样往复.最后一次不回头.如果要接a次

Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案

You're trying to set the record on your favorite video game. The game consists of N levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower. Spec

codeforces 701 D. As Fast As Possible(数学题)

题目链接:http://codeforces.com/problemset/problem/701/D 题意:给你n个人,每个人走路的速度v1,有一辆车速度为v2,每次可以载k个人,总路程为l,每个人只能上一次车,问最少需要多少时间把所有人送到终点 题解:首先要使的时间最短肯定是所有人同时到达终点,那么肯定每人坐车的时间是相同的. 不妨设一下车一趟来回的时间为t,乘车距离为a.可以得到 (l-a)/v1+a/v2=t*(gg-1)+a/v2(意思就是最后一批人乘车到达终点时所有人同时到达终点)

Codeforces Round #364 As Fast As Possible

二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行. 使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力. #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<map> #include<queue>

【推导】Codeforces Round #364 (Div. 2) D. As Fast As Possible

一种方法是二分总时间,复杂度O(nlogn). 另外我们可以证明,当所有人同时到达终点的时候,是最优的,因为没有人的时间"浪费"了. 我们又发现,每个人的运动过程总是两段,要么是走路,要么是坐车.于是每个人的运动都是等价的(坐车的时间也相等,走路的时间也相等). 这里借用一下这个推导,懒得写了. (http://blog.csdn.net/say_c_box/article/details/52001850) 根据上面的过程得出d以后,于是有d*(组数-1)+l1=l,然后就可以解出l

第六周周赛——AK机会不易得,好好把握题解(出自HDU5650,codeforces 616A,624A,659A,655A,658A)

A题: A题题目链接 题目描写叙述: 位运算 TimeLimit:1000MS  MemoryLimit:65536KB 64-bit integer IO format:%I64d Problem Description 已知一个包括 n 个元素的正整数集合S.设 f(S) 为集合S中全部元素的异或(XOR)的结果. 如:S={1,2,3}, 则 f(S) = 0. 给出集合S,你须要计算 将全部f(s)进行异或后的值, 这里 s?S. Input 多组測试数据.第一行包括一个整数T(T≤20

codeforces:Prefix Sums

题目大意: 给出一个函数P,P接受一个数组A作为参数,并返回一个新的数组B,且B.length = A.length + 1,B[i] = SUM(A[0], ..., A[i]).有一个无穷数组序列A[0], A[1], ... 满足A[i]=P(A[i-1]),其中i为任意自然数.对于输入k和A[0],求一个最小的下标t,使得A[t]中包含不小于k的数值. 其中A[0].length <= 2e5, k <= 1e18,且A[0]中至少有两个正整数. 数学向的题目.本来以为是个找规律的题目