【45.61%】【codeforces 701D】As Fast As Possible
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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 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.
题解
数学问题.
最后的时间取决于最后一拨到终点的人的时间.
因此肯定是这样:先将一波人载到终点前的某个位置。
然后这辆车再回来载另外一拨人。然后两拨人(方便起见先假设只要载两次就能载完)同时到达终点。
这样是最优的方案。
可以肯定每个人在车上的时间是相同的,且所有人同时到达终点。
可以这么理解:
假如每个人在车上的时间不同。
最后一波人到终点的时候,假设有人先到了终点则总是可以调整那堆人少坐一会车,最后这波人多做一会车。
最后每个人在车上的时间就是相同的了,且所有人都能够同时到达终点。
同时到达可以这么理解,设所有人在车上经过的路程为g,则 (l-g)/v1 + g/v2为每个人最后到达的时间。如果在车上的时间相同则g相同,那么最后的时间也就相同了(l,v1,v2都是确定的量);
因为所有人在车上的时间是相同的。
则设所有人在车上经过的路程为g,一辆车从接到一波人开始,一直到它返回又接到第二波人的时间间隔为△t;第二拨人原来的位置
为x,等车又返回载它们的时候位置变成x+△t*v1
则有
x+△t*v1=x+g-(△t-g/v2)*v2; ····①
右边的(△t-g/v2)是这辆车接人到一个合适的位置后又往回走的距离;
根据①式可得
△t=(2g)/(v1+v2); ·····②
设r = (n/k)+((n%k)?1:0);
这个r就是这辆车需要载的趟数
则有
△t*(r-1)+g/v2 = (l-g)/v1 + g/v2; ····③
左边是车到达的时间,右边是人到达的时间;
(l-g)/v1就是每波人走路的时间了,g/v则是在车上的时间
右边r-1表示需要往返r-1次,然后最后一次直接把最后一拨人载到终点即可
由③式可得
g= l(v1+v2)/(2*v1(r-1)+v1+v2);
答案就是(l-g)/v1 + g/v2;
#include <cstdio>
int n,k,r;
double l, v1, v2;
int main()
{
scanf("%d%lf%lf%lf%d", &n, &l, &v1, &v2, &k);
r = n / k + ((n%k) ? 1 : 0);
double g = (l*(v1 + v2)) / (2 * v1*((r - 1)*1.0) + v1 + v2);
double ans = (l - g) / v1 + g / v2;
printf("%.10lf\n", ans);
return 0;
}
【45.61%】【codeforces 701D】As Fast As Possible的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- codeforces 701D D. As Fast As Possible(数学)
题目链接: D. As Fast As Possible time limit per test 1 second memory limit per test 256 megabytes input ...
- 【45.65%】【codeforces 560B】Gerald is into Art
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【搜索】【并查集】Codeforces 691D Swaps in Permutation
题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【链表】【模拟】Codeforces 706E Working routine
题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别 ...
- 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions
题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < ...
随机推荐
- win8.1 “服务器运行失败”的解决方法
平台:win8.1 SP1 问题:安装QQ安全管家又卸载后出现了奇怪的问题,1.在桌面点右键→个性化时,提示“服务器运行失败”.2.右键点击“这台电脑”,选择“属性”时没有反应.3.开始屏幕里随便选择 ...
- JS学习笔记 - fgm练习 - 网页换肤
总结: 1. 点击按钮,div内部变色,边框保持颜色不变. 实现原理:其实本来就把background 和 border 分别设置了同一个颜色,看似是一个整体,其实本来就是分开的. 那么点击的时候,只 ...
- Webpack学习手册
多端阅读<Webpack官方文档>: 在PC/MAC上查看:下载w3cschool客户端,进入客户端后通过搜索当前教程手册的名称并下载,就可以查看当前离线教程文档.下载Webpack官方文 ...
- VMware Ubuntu安装具体过程
不是每个程序猿都必须玩过linux,仅仅是博主认为如今的非常多server都是linux系统的,而自己属于那种前端也搞.后台也搞,对框架搭建也感兴趣,可是非常多生产上的框架和工具都是安装在server ...
- iOS改动UIButton setTitle字体颜色和调整字体位置
调整Title字体位置 [button setTitleEdgeInsets:UIEdgeInsetsMake(10, 0, 0, 0)]; 四个參数分别代表:上边界,左边界.下边界,右边界 改动UI ...
- 从0開始学习 GitHub 系列之「07.GitHub 常见的几种操作」
之前写了一个 GitHub 系列,反响非常不错,突然发现居然还落下点东西没写,前段时间 GitHub 也改版了,借此机会补充下. 我们都说开源社区最大的魅力是人人多能够參与进去,发挥众人的力量,让一个 ...
- mysql 悲观锁 的运用
悲观锁: 它指的是对数据被外界(包括本系统当前的其他事务,以及来自外部系统的事务处理)修改持保守态度,因此,在整个数据处理过程中,将数据处于锁定状态.悲观锁的实现,往往依靠数据库提供的锁机制(也只有数 ...
- 常用有效检测数据库运行状态SQL脚本
1.查看数据库中不为 InnoDB 引擎的表 SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE FROM information_schema.TABLES W ...
- cocos2d-x win8下的环境配置和建立项目
cocos2dx 跨平台.可是看网上说开发最合适还是在vs2010中,基本是编完后再移植到安卓. 1.去官网下载源代码2.2.3版本号的. 2.然后运行根文件夹下的build-win32.bat(须要 ...
- 【C#】万事开头难(二)<机房重构>
前言 机房将要进行完了,之所以仍然使用这个题目,是由于我想告诉自己.无论面对多么未知的事物.不要害怕,去做就好.在这么多天的机房重构中,发现了好多问题,也攻克了好多问题,今天,就把我解决的问题分享给大 ...