codeforces 701D D. As Fast As Possible(数学)
题目链接:
1 second
256 megabytes
standard input
standard 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 kpeople (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 题意: 现在给了两个速度,n个人,长为l的路,车的速度快,人的速度,车的容量为k;
现在问这n个人走完l的路后用时最少是多少; 思路: 我是二分车第一次载人的时长,计算最后一次载人是否恰好到达终点;
精度被卡我就把二分的次数上限限定了才过,好像直接有公式; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=500+10;
const double eps=1e-14; int n,k;
double L,v1,v2; int check(double x)
{
double t=x,pos=v2*t;
For(i,2,n)
{
double tempt=t,temppos=pos;
pos=(temppos-tempt*v1)*v2/(v2-v1)+(temppos-tempt*v1)*v1/(v1+v2)+tempt*v1;
t=(temppos-tempt*v1)/(v2-v1)+(temppos-tempt*v1)/(v1+v2)+tempt;
}
if(pos>=L)return 0;
return 1;
} int main()
{
scanf("%d%lf%lf%lf%d",&n,&L,&v1,&v2,&k);
if(k>=n)printf("%.10lf",L/v2);
else
{
if(n%k==0)n=n/k;
else n=n/k+1;
double l=0,r=L/v2;
int cnt=0;
while(r>=l+eps&&cnt<1000)
{
cnt++;
double mid=(l+r)/2;
if(check(mid))l=mid;
else r=mid;
}
r=(l+r)/2;
double ans=(L-r*v2)/v1+r;
printf("%.10lf\n",ans);
}
return 0;
}
codeforces 701D D. As Fast As Possible(数学)的更多相关文章
- 【45.61%】【codeforces 701D】As Fast As Possible
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- Codeforces Round #364 (Div. 2) D. As Fast As Possible 数学二分
D. As Fast As Possible 参考:https://blog.csdn.net/keyboardmagician/article/details/52769493 题意: 一群大佬要走 ...
- Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案
You're trying to set the record on your favorite video game. The game consists of N levels, which mu ...
- Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学
E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...
- Codeforces Round #207 (Div. 1)B(数学)
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...
- Codeforces 810C Do you want a date?(数学,前缀和)
C. Do you want a date? time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- codeforces 2B The least round way(DP+数学)
The least round way 题目链接:http://codeforces.com/contest/2/problem/B ——每天在线,欢迎留言谈论.PS.本题有什么想法.建议.疑问 欢迎 ...
- Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
随机推荐
- [NSURL URLWithString:] 返回nil
具体问题原因是url中输入的有中文,那么这个就看作非法的字符无法识别.这种的必须使用post方式来发送消息.具体为: tmp = mainurl; [parameters app ...
- win7阻止iis开机启动
https://zhidao.baidu.com/question/111234812.html 1.在"开始/运行/" 输入"services.msc" 启动 ...
- SilverLight:基础控件使用(4)-日期显示和选择类控件
ylbtech-SilverLight-Basic-Control:基础控件使用(4)-日期显示和选择类控件 Calendar,DatePicker 1.A,返回顶部 Calendar控件(日期控件) ...
- maven编译maven-surefire-plugin插件报错
1.编译错误信息: [INFO] ------------------------------------------------------------------------ [ERROR] Fa ...
- Unity3D:Gizmos画圆(原创)
Unity3D引擎技术交流QQ群:[21568554] Gizmos是场景视图里的一个可视化调试工具. 在做项目过程中.我们常常会用到它,比如:绘制一条射线等. Unity3D 4.2版本号截至.眼下 ...
- js eval 解析字符串
//带变量的字符串var str = 'var a=1; var b=2;'; eval(str); alert(a+b);//结果 3: //数组字符串var arrStr = "[1,2 ...
- Python web 框架:web.py
web.py 是一个Python 的web 框架,它简单而且功能强大.web.py 是公开的,无论用于什么用途都是没有限 制的. web.py 安装: pip install web.py 下面开始我 ...
- MySQL优化之——日志
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46790451 MYSQL里的日志主要分为4类,使用这些日志文件.能够查看MYSQL ...
- web前端面试系列 - 数据结构(两个栈模拟一个队列)
一. 用两个栈模拟一个队列 思路一: 1. 一个栈s1作为数据存储,另一个栈s2,作为临时数据存储. 2. 入队时将数据压人s1 3. 出队时将s1弹出,并压人s2,然后弹出s2中的顶部数据,最后再将 ...
- Windows 7 & Ubuntu 14.04完美双系统安装及系统引导配置----校园网Mentohust配置
本文写于完美安装双系统之后,所以图片会不全然.主要目的是总结下注意事项.备用. 一.Win7-64-旗舰版U盘安装 win7-64-旗舰版纯净版下载,下载安装后仅仅有1个驱动人生! 附刻盘工具激活工具 ...