As Fast As Possible
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.
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 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的更多相关文章
- opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较
opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较 参考: http://wenku.baidu.com/link?url=1aDYAJBCrrK-uk2w3sSNai7h52x_ ...
- 基于Fast Bilateral Filtering 算法的 High-Dynamic Range(HDR) 图像显示技术。
一.引言 本人初次接触HDR方面的知识,有描述不正确的地方烦请见谅. 为方便文章描述,引用部分百度中的文章对HDR图像进行简单的描述. 高动态范围图像(High-Dynamic Range,简称HDR ...
- Fast RCNN 训练自己的数据集(3训练和检测)
转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ https://github.com/YihangLou/fas ...
- Fast RCNN 训练自己数据集 (2修改数据读取接口)
Fast RCNN训练自己的数据集 (2修改读写接口) 转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ http ...
- 网格弹簧质点系统模拟(Spring-Mass System by Fast Method)附源码
弹簧质点模型的求解方法包括显式欧拉积分和隐式欧拉积分等方法,其中显式欧拉积分求解快速,但积分步长小,两个可视帧之间需要多次积分,而隐式欧拉积分则需要求解线性方程组,但其稳定性好,能够取较大的积分步长. ...
- 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 目录 作者和相关链接 方法概括 ...
- 论文笔记--Fast RCNN
很久之前试着写一篇深度学习的基础知识,无奈下笔之后发现这个话题确实太大,今天发一篇最近看的论文Fast RCNN.这篇文章是微软研究院的Ross Girshick大神的一篇作品,主要是对RCNN的一些 ...
- [转]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 ...
- FAST特征点检测features2D
#include <opencv2/core/core.hpp> #include <opencv2/features2d/features2d.hpp> #include & ...
- TCP Fast Open
We know that Web services use the TCP protocol at the transport layer. Standard TCP protocol to thre ...
随机推荐
- ios文本框基本使用,以及所有代理方法的作用
/* UITextField文本输入框 */ UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 50 ...
- 菜鸟认识揭开DLL木马
相信经常玩木马的朋友们都会知道一些木马的特性,也会有自己最喜爱的木马,不过,很多朋友依然不知道近年兴起的“DLL木马”为何物.什么是“DLL木马”呢?它与一般的木马有什么不同? 一.从DLL技术说起 ...
- servlet第3讲(中集)----同一用户的不同页面共享数据
5.session 5.1session概述 5.2.session应用举例
- App Store 升级问题
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- 在CentOS 7下ISCSI和多路径部署文档【转】
部署环境 设备:MD3860i, R630, S4820T(生产网络), N2024(管理网络) 操作系统:Centos 7 默认管理口的地址:A控192.168.129.101, B 控192.16 ...
- Hibernate 关系映射方式(1)
来源:本文转载自:http://blog.csdn.net/huangaigang6688/article/details/7761310 Hibernate映射解析——七种映射关系 首先我们了解一个 ...
- 笨方法学python--提问
1 实现 用户在终端进行输入 的方法 print "how old are you?", age = raw_input() 该地方,第1名后面加逗号,然后必须换行 2 若要限制用 ...
- 文件描述符和exec() close_on_exec
#include <fcntl.h> #include <iostream> #include <unistd.h> using namespace std; in ...
- 【转】linux ls -l的详解
原文:http://blog.csdn.net/sjzs5590/article/details/8254527 以root的家目录为例: 可以看到,用ls -l命令查看某一个目录会得到一个7个字段的 ...
- typeof判断类型(数组类型得用instanceof)
var a= 1; console.log(typeof a); var b= '1'; console.log(typeof b); var c; console.log(typeof c); va ...