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 ...
随机推荐
- 51Nod 1095 Anigram单词
熟练使用map即可,不然用vector会超时 #include <iostream> #include <cstring> #include <string> #i ...
- C#操作高低位
比如一个数 想把高位 与地位拆开,分别显示 可以用这个办法 x=(uint16)(x>>8) (高字节向右移动8位 相当于*256) X=(UINT16)(X &0X00FF) ...
- mysql-SQL语法
细节查询:http://www.w3school.com.cn/sql/index.asp 1 DDL-data difinition lanuage数据定义语句 使我们有能力创建或删除表格,我们也可 ...
- python之文件的读写
读 r 读写模式 r+ 如果打开文件时没有指定模式,默认只读,如果使用r或r+,文件不存在时会报错 写 w 写读模式 w+ w模式会清空原有的文件内容 追加 a 追加读 ...
- Codeforces Round #261 (Div. 2) C
Description Recently Pashmak has been employed in a transportation company. The company has kbuses a ...
- Python Unicode and str
http://stackoverflow.com/questions/18034272/python-str-vs-unicode-types unicode is a character set. ...
- 转 ORACLE数据库ORA-00392 log 4 of thread 1 is being cleared, operation not allowed错误
现象: 数据库在做to-time recovery, 时候,restore and recover 都是正常的,但是最后一步open resetlogs 报错如下 ORA-00392 原因: 因为是在 ...
- Apex 使用和学习
ref doc http://o7planning.org/en/10345/oracle-apex-tutorial-for-beginners (change from web to pdf) ...
- Asp.net MVC + Vue.js
@{ Layout = null; } <!DOCTYPE html><html> <head> <meta charset="UTF-8" ...
- AJPFX辨析Java中运算符 ++ 和 += 的区别
我们都知道Java中 ++ 和 +=1 都是把数字增加一后,把值赋给左边,那二者有什么区别呢? i+=1 运行的底层Heap申请一个区域存放i,在数据区域开劈一个区域存放1,2个内存段被数据被送入到 ...