Codeforces 5D Follow Traffic Rules

【题意概述】
某个物体要从A途经B到达C,在通过B的时候速度不能超过vd. 它的加速度为a,最大速度为vm;AB之间距离为d,AC之间距离为L; 问物体最少花多少时间到达C.
【题解】
分情况讨论。
若物体一直加速,通过B之前速度已经超过了vd,那么显然物体必须先加速后减速才能保证通过B是速度为vd.
先加速后减速也分为两种情况:加速后立即减速、加速后保持最大速度vm一段时间后再减速。
通过了B之后物体从速度vd一直加速,直至到达C或者达到最大速度vm.
若物体无法在通过B之前达到vd,那么显然物体一直加速,之后保持最大速度vm前进即可。
做完了以上的分析,我们就可以结合物理公式直接计算。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define rg register
#define N 200010
using namespace std;
int a,vm,l,d,vd;
double ans;
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
int main(){
a=read(); vm=read(); l=read(); d=read(); vd=read();
double t0=1.0*vd/a;
double s0=0.5*vd*t0;
// printf("%.2lf %.2lf\n",t0,s0);
if(s0<d&&vm>=vd){
// puts("a1");
double t1=1.0*(vm-vd)/a;
double s1=(vd+vm)*t1;
if(s0+s1<=d){
ans=t0+t1+t1+(d-s0-s1)/vm;
}
else{
double delta=*vd*vd-*a*(s0-d);
t1=1.0*(-*vd+sqrt(delta))/(*a);
ans=t0+t1+t1;
}
// printf("%.7lf\n",ans);
int d2=l-d;
double t2=1.0*(vm-vd)/a;
double s2=(vd+vm)*t2/;
if(s2<d2){
// puts("c1");
ans+=t2+1.0*(d2-s2)/vm;
}
else{
// puts("c2");
double vx=sqrt(vd*vd+*a*d2);
double t3=(vx-vd)/a;
ans+=t3;
}
}
else{
// puts("a2");
double v=sqrt(*a*d);
// printf("%.2lf\n",v);
if(v>=vm){
double t1=1.0*vm/a;
ans=t1+(d-vm*t1/)/vm+1.0*(l-d)/vm;
}
else{
double t1=1.0*v/a;
ans=t1;
// printf("%.7lf\n",ans);
int d2=l-d;
double t2=1.0*(vm-v)/a;
double s2=(v+vm)*t2/;
// printf("%.2lf\n",s2);
if(s2<d2){
ans+=t2+1.0*(d2-s2)/vm;
}
else{
double vx=sqrt(v*v+*a*d2);
double t3=(vx-v)/a;
ans+=t3;
}
}
}
printf("%.12lf\n",ans);
return ;
}
Codeforces 5D Follow Traffic Rules的更多相关文章
- Codeforces Beta Round #5 D. Follow Traffic Rules 物理
D. Follow Traffic Rules 题目连接: http://www.codeforces.com/contest/5/problem/D Description Everybody kn ...
- codeforces 5D
D. Follow Traffic Rules time limit per test 1 second memory limit per test 64 megabytes input standa ...
- 【codeforces 29B】Traffic Lights
[题目链接]:http://codeforces.com/problemset/problem/29/B [题意] 一辆车; 让从A开到B; 然后速度是v; (只有在信号灯前面才能停下来..否则其他时 ...
- Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划
C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de ...
- 【17.76%】【codeforces round 382C】Tennis Championship
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Traffic Lights
Traffic Lights time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #382 (Div. 2) C. Tennis Championship 斐波那契
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Painting The Wall 期望DP Codeforces 398_B
B. Painting The Wall time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #256 (Div. 2) 题解
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- C# BitmapData使用说明
C# BitmapData使用说明msdn关于BitmapData原文解释地址:http://msdn.microsoft.com/zh-cn/library/5ey6h79d(v=vs.110).a ...
- div里面放img
div里面放img的时候 会出现包裹不住的情况,这个时候 只要将img { width:100%,height:100% },就可以解决问题了
- nginx上游模块
1 概念 The ngx_http_upstream_module is used to define groups of servers that can be referenced by the ...
- Python入门小练习 002 批量下载网页链接中的图片
我们常常需要下载网页上很多喜欢的图片,但是面对几十甚至上百张的图片,一个一个去另存为肯定是个很差的体验. 我们可以用urllib包获取html的源码,再以正则表达式把匹配的图片链接放入一个list中, ...
- SpringMVC-核心配置文件spring-mvc.xml
@Spring-MVC.xml @MVC的注解驱动 Bean模式 上面源码的配置我们看到了,其中映射器和适配器的注解模式是过时的所以我们需要重新配置一下. <!-- 配置处理器映射器 --> ...
- ogg 监控脚本
section 1: #! /bin/sh PATH=/usr/local/bin:$PATHORACLE_SID=statdb ORAENV_ASK=NO. oraenv > /dev/nul ...
- 简要记录下localStorage在项目中的应用之一
localStorage作为HTML5本地存储web storage特性的API之一,主要作用是将数据保存在客户端中.localStorage保存的数据,一般情况下是永久保存的,也就是说只要采用loc ...
- LNMP笔记:解决mail函数不能发送邮件
用LNMP环境,在探针里测试发送邮件,失败了.已经确定mail()函数是开启的. 问题根源 没有安装或启动 sendmail 组件 解决办法 我是新手,命令不熟,所以写的很详细,老鸟勿喷哦 1.重新安 ...
- (转)编码剖析@Resource注解的实现原理
http://blog.csdn.net/yerenyuan_pku/article/details/52860046 上文我们已经学会使用@Resource注解注入属性.学是学会了,但也仅限于会使用 ...
- Ubuntu 16.04 LTS下matplotlib安装出错
使用命令sudo pip3 install matplotlib已知报错,用同样的命令安装numpy和opencv却没有,因此重装linux系统两次都没有解决(我是在Vmware中创建的).报错如下: ...