Codeforces700A As Fast As Possible 数学推理
来源:互联网 发布:c语言竖线 编辑:程序博客网 时间:2024/05/16 07:51
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.
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.
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.
5 10 1 2 5
5.0000000000
3 6 1 2 1
4.7142857143
In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.
题意就是求一群小学生都到达目的地的最短时间,有 bus 这一种交通工具,但每个小学生只能坐一次 bus 。因此,每个小学生到达目的地的时间,就是坐 bus 的时间+走路的时间,最短时间显然取决于坐 bus 路程最短的那人。那么,最优的情况应该就是,所有人坐 bus 的路程都一样,这样就能够保证最快的和最慢的所花的时间相同。然后,我们先考虑简单的情况,由于 bus 来回趟数是和 n/k 有关的,那么先分析 n/k 为 2 的情况,该情况下, bus 先送一半人,再回来接另一半人。我们可以假设 bus 载人走过路径为 K*l ,那么 走路的路径为 (1-K)*l ,那么,由 bus 需要回去接另一波小学生,我们可以计算得到:
#include <cstdio>#include <map>#include <set>#include <vector>#include <queue>#include <stack>#include <cmath>#include <algorithm>#include <cstring>#include <string>using namespace std;#define INF 0x3f3f3f3ftypedef long long LL;int main(){ int n,l,v1,v2,k; while(~scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k)){ if(k>=n){ printf("%.10lf\n",l*1.0/v2); continue; } int t=(n-1)/k; double s=v2*1.0/v1; double kk=(1+s)/(3+s); double temp=kk+t*(1-kk); temp=l*1.0/(temp*v1); printf("%.10lf\n",temp*(kk/s+t*(1-kk))); } return 0;}
- Codeforces700A As Fast As Possible 数学推理
- Codeforces700A Fast As Possible(二分+找规律)
- As Fast As Possible
- cf/Codeforces Round #364 D As Fast As Possible 数学
- CodeForces - 701D As Fast As Possible (数学推导)
- CF 700A As Fast As Possible
- codeforces 701 D. As Fast As Possible
- Codeforces Round #364 (Div. 2) D. As Fast As Possible(数学推导)
- Codeforces Round #364(Div. 2) D. As Fast As Possible 【数学】
- Codeforces Round #364 (Div. 2) D As Fast As Possible(数学)
- Codeforces Round #364 (Div. 1)A. As Fast As Possible(数学)
- codeforces#364DAs Fast As Possible
- Codeforces Round #364 (Div. 2) D. As Fast As Possible
- Codeforces Round #364 (Div. 1) A - As Fast As Possible
- Codeforces Round #364 (Div. 2) D. As Fast As Possible
- div.2/D. As Fast As Possible<数学题,二分>
- codeforces 364 div2 D As Fast As Possible
- Codeforces Round #364 (Div. 1) A. As Fast As Possible
- 【转载】逃离adapter的地狱-针对多个View type的组合实现方案
- Kth Smallest Element in a BST
- Map获取键值的几种遍历方法
- 通过火车票还原身份证
- CodeForces 686B 冒泡排序
- Codeforces700A As Fast As Possible 数学推理
- Python异常处理机制
- 欧拉函数求法与应用
- Servlet整合Log4j日志记录
- HDU Problem 1052 Tian Ji -- The Horse Racing 【贪心】
- TCP三次握手和劫持原理与实例
- Hibernate学习笔记----映射继承关系
- sql关键语句详解
- 如何解决有限无限同时上网的问题