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 ...
随机推荐
- HDU 3416 Marriage Match IV
最短路+最大流 #include<cstdio> #include<cstring> #include<string> #include<cmath> ...
- scala map
map 返回元组 下面是如果不存在key 报错 a.(2) 下面两种方式 不同的写法. 如果存在 Some(2) 不存在 None a get 2 a.get(2) getOrElse 如果不存在 回 ...
- WebViewJavascriptBridge详细使用
前言 WebViewJavascriptBridge是支持到iOS6之前的版本的,用于支持native的iOS与javascript交互.如果需要支持到iOS6之前的app,使用它是很不错的.本篇讲讲 ...
- Entity Framework技巧系列之七 - Tip 26 – 28
提示26. 怎样避免使用不完整(Stub)实体进行数据库查询 什么是不完整(Stub)实体? 不完整实体是一个部分填充实体,用于替代真实的对象. 例如: 1 Category c = new Cate ...
- print a float number with 3 digits following
just use the java's printf function. It is like C's printf. System.out.printf("%.3f\n", x) ...
- LVS负载均衡中arp_ignore和arp_annonuce参数配置的含义
先简单的介绍下关于LVS负载均衡 LVS(Linux Virtual Server)Linux服务器集群系统 针对高可伸缩,高可用服务的需求,给予IP层和内容请求分发的负载均衡调度解决方法,并在Li ...
- python 多线程 paramiko实现批量命令输入输出
远程批量执行命令 实现多线程执行 速度快 实现多并发登录 #-*- coding: utf-8 -*- #!/usr/bin/python import paramiko import threadi ...
- zf-分页后台代码
java : public ResultPage getDeptList(int page, int pageRows) throws Exception { String hql="fro ...
- echarts学习总结(一):图表溢出窗口,图表数据窗口显示不全
如上图所示:echarts图形左面的数据没有完全显示 只需在option中定义一下grid,例如: gri ...
- OpenGL ES之glUniform函数
函数名: glUniform 功能: 为当前程序对象指定Uniform变量的值.(译者注:注意,由于OpenGL ES由C语言编写,但是C语言不支持函数的重载,所以会有很多名字相同后缀不同的函数版本存 ...