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 ...
随机推荐
- Hdu 5439 Aggregated Counting (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online 找规律)
题目链接: Hdu 5439 Aggregated Counting 题目描述: 刚开始给一个1,序列a是由a[i]个i组成,最后1就变成了1,2,2,3,3,4,4,4,5,5,5.......,最 ...
- Ubuntu 安装 node
ubuntu安装node和npm的命令行命令: sudo apt install nodejs-legacy sudo apt install npm 最新版本安装方法 1.安装npm sudo ap ...
- 18.3.2从Class上获取信息(构造器)
获取构造器信息 package d18_3_1; import java.lang.reflect.Constructor; import java.util.Arrays; /** * 获取构造器的 ...
- mysql中迅速插入百万条测试数据的方法
对比一下,首先是用 mysql 的存储过程弄的: 复制代码代码如下: mysql>delimiter $ mysql>SET AUTOCOMMIT = 0$$ mysql> crea ...
- 142 Linked List Cycle II 环形链表 II
给一个链表,返回链表开始入环的第一个节点. 如果链表无环,则返回 null.说明:不应修改给定的链表.补充:你是否可以不用额外空间解决此题?详见:https://leetcode.com/proble ...
- SpringBoot项目不占用端口启动
@EnableScheduling @SpringBootApplication public class Application { public static void main(String[] ...
- AJPFX总结string类和简单问题
String表示字符串,所谓字符串,就是一连串的字符;String是不可变类,一旦String对象被创建,包含在对象中的字符序列(内容)是不可变的,直到对象被销毁://一个String对象的内容不能变 ...
- AJPFX关于面向对象之封装,继承,多态 (下)
(3)private: 对于对于成员来说:只能在该成员隶属于的类中访问. 对于类来说:类不可以声明为private. 4)protected: 对于对于成员来说:相同包中的类可以访问(包访问权限):基 ...
- hadoop的安装和配置
hadoop安装 在Apache Hadoop主页的下载页面https://hadoop.apache.org/releases.html选择版本进行下载: 下载下来的是压缩包: 将压缩包使用Xftp ...
- Activity的创建、生命周期
Activity是Android四大组件之一.一个Activity负责管理一个界面. 创建一个Activity: New -> Activity -> 选择要创建的Activity类型(一 ...