As Fast As Possible

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.

分析:参考自http://blog.csdn.net/libin66/article/details/52004623

   首先最优情况下应有每个人坐公交时间和走路时间都相等(保证同时到达)。

   这些人可以分为cnt=(n-k+1)/k部分;

   设每个人坐bus路程L1,第二波人遇见bus时时间为T,则有(V1+V2)*T=2L1;

   那么第二波人走了d=TV1=2L1V1/(V1+V2);

   以后每一波人坐bus前都会继续多走d的路程,那么最后一波人走的路程(cnt-1)*d=L-L1;

    (保证坐bus恰好到达终点)

   则解得L1=L*(V1+V2)/(2*cnt*V1-V1+V2),总时间t=L1/V2+(L-L1)/V1;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,l,v1,v2,k;
int main()
{
int i,j,t;
cin>>n>>l>>v1>>v2>>k;
int cnt=(n+k-)/k;
double bus_path=1.0*l*(v1+v2)/(*cnt*v1-v1+v2);
double ans=bus_path/v2+(l-bus_path)/v1;
printf("%.10f\n",ans);
//system ("pause");
return ;
}

补二分做法:二分结束时间,然后根据方法一算出最后一组在期望时间能够走的总路程,与目标路程比较;

代码:

#include <bits/stdc++.h>
using namespace std;
int n,m,l,v1,v2;
int main()
{
int i,j,k,t;
cin>>n>>l>>v1>>v2>>k;
int cnt=(n+k-)/k;
double tl=,tr=(double)l/v1;
while(tr-tl>1e-)
{
double mid=(tl+tr)/;
double l1=(mid-(double)l/v1)*v1*v2/(v1-v2),p=(cnt-)**l1/(v1+v2)*v1+l1;
if(p<=l)tr=mid;
else tl=mid;
}
printf("%.10f\n",tl);
//system("pause");
return ;
}

As Fast As Possible的更多相关文章

  1. opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较

    opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较 参考: http://wenku.baidu.com/link?url=1aDYAJBCrrK-uk2w3sSNai7h52x_ ...

  2. 基于Fast Bilateral Filtering 算法的 High-Dynamic Range(HDR) 图像显示技术。

    一.引言 本人初次接触HDR方面的知识,有描述不正确的地方烦请见谅. 为方便文章描述,引用部分百度中的文章对HDR图像进行简单的描述. 高动态范围图像(High-Dynamic Range,简称HDR ...

  3. Fast RCNN 训练自己的数据集(3训练和检测)

    转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ https://github.com/YihangLou/fas ...

  4. Fast RCNN 训练自己数据集 (2修改数据读取接口)

    Fast RCNN训练自己的数据集 (2修改读写接口) 转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ http ...

  5. 网格弹簧质点系统模拟(Spring-Mass System by Fast Method)附源码

    弹簧质点模型的求解方法包括显式欧拉积分和隐式欧拉积分等方法,其中显式欧拉积分求解快速,但积分步长小,两个可视帧之间需要多次积分,而隐式欧拉积分则需要求解线性方程组,但其稳定性好,能够取较大的积分步长. ...

  6. XiangBai——【AAAI2017】TextBoxes_A Fast Text Detector with a Single Deep Neural Network

    XiangBai--[AAAI2017]TextBoxes:A Fast Text Detector with a Single Deep Neural Network 目录 作者和相关链接 方法概括 ...

  7. 论文笔记--Fast RCNN

    很久之前试着写一篇深度学习的基础知识,无奈下笔之后发现这个话题确实太大,今天发一篇最近看的论文Fast RCNN.这篇文章是微软研究院的Ross Girshick大神的一篇作品,主要是对RCNN的一些 ...

  8. [转]Amazon DynamoDB – a Fast and Scalable NoSQL Database Service Designed for Internet Scale Applications

    This article is from blog of Amazon CTO Werner Vogels. -------------------- Today is a very exciting ...

  9. FAST特征点检测features2D

    #include <opencv2/core/core.hpp> #include <opencv2/features2d/features2d.hpp> #include & ...

  10. TCP Fast Open

    We know that Web services use the TCP protocol at the transport layer. Standard TCP protocol to thre ...

随机推荐

  1. Oracle字符串操作[转:http://www.cnblogs.com/xd502djj/archive/2010/08/11/1797577.html]

    ORACLE 字符串操作 1 字符串连接   SQL> select 'abc' || 'def' from dual; 'ABC'|------abcdef 2 小写SQL>select ...

  2. vc里面怎样实现对话框之间传递变量的值

    Dialog1的类名是CDialog1, 头文件是dialog1.h.里有成员变量CString str1, str2;Dialog2的类名是CDialog2, 头文件是dialog2.h.里有成员变 ...

  3. DLT(Diagnostic Log and Trace)嵌入式系统程序运行记录

    http://blog.csdn.net/yanlinembed/article/details/49837975 DLT的使用有属于Application范畴与Context范畴.在使用DLT时,需 ...

  4. 确定当前Python环境中的site-packages目录位置

    引入“搜索路径”这个概念是因为在使用import语句时,当解释器遇到import语句,如果模块在当前的搜索路径就会被导入. 搜索路径是一个解释器会先进行搜索的所有目录的列表. 那么python如何添加 ...

  5. 自定义cell,根据数据源,要对cell的布局进行调整,没有实现调整的相应效果

    自定义cell,用于两种显示情况,首次进来A种情况(主材页面),正确显示,然后切换B种情况(辅材情况),可以正确显示,但是当再次切换回A种情况(主材情况)的时候,主材cell不能正常显示了,遗留的B中 ...

  6. s7-300 第二讲

  7. JDBC技术

    JDBC是java程序操作数据库的API 一 JDBC连接数据库的过程 (1) 注册数据库驱动 Class.forName("com.mysal.jdbc.Dirver")     ...

  8. Android OpenGL ES(四)关于EGL .

    OpenGL ES的javax.microedition.khronos.opengles 包定义了平台无关的GL绘图指令,EGL(javax.microedition.khronos.egl ) 则 ...

  9. UVA 10277 Boastin' Red Socks

    #include <iostream> #include<cstdio> #include<cstring> using namespace std; unsign ...

  10. sockaddr_u详解

    struct sockaddr { unsigned short sa_family;     /* address family, AF_xxx */ char sa_data[14];       ...