这个题是个高中的物理公式,只要细节处理好就能过(现在最怕的就是细节啊)~~
题目大意:
城市A、B之间有一条路,长度为l,在距离A城市d的位置放置了限速标志,意味着到那个点的时候速度必须不大于限制速度。现有一车在城市A出发,车的加速度为a,最大速度为v,求通过这条路的最小时间。车出发时的速度为零。
解题思路:
套物理公式,分类讨论
下面是代码:
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <cctype>
#include <algorithm>
#define eps 1e-10
#define pi acos(-1.0)
#define inf 107374182
#define inf64 1152921504606846976
#define lc l,m,tr<<1
#define rc m + 1,r,tr<<1|1
#define zero(a) fabs(a)<eps
#define iabs(x) ((x) > 0 ? (x) : -(x))
#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))
#define clearall(A, X) memset(A, X, sizeof(A))
#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))
#define memcopyall(A, X) memcpy(A , X ,sizeof(X))
#define max( x, y ) ( ((x) > (y)) ? (x) : (y) )
#define min( x, y ) ( ((x) < (y)) ? (x) : (y) )
/**
20 40
10000 1 30
**/
using namespace std;
int main()
{
double templ,ans,a,v,l,d,w;
cin>>a>>v>>l>>d>>w;
if(w<=v) //当限速小于最大速度时
{
templ=w*w/2/a;//由零提高到限制速度所需要的路途长度
if(templ<d)//如果已经提高到限制速度却没到达限制标志处
{
//这一段距离可以加速再减速
ans = sqrt(2*templ/a);
double dis=d-templ;
dis/=2;
if((v*v-w*w)/2/a<=dis)//若加速到最高速度还没有到这段路经的一半 需要匀速行驶
{
double t = (v-w)/a;
t+=(dis-(v*v-w*w)/2/a)/v;
ans+=2*t;
templ=d;
}
else //不需要匀速行驶
{
double t = sqrt(2*(templ+dis)/a)-ans;
ans+=2*t;
templ=d;
}
}
else if(templ>=d&&templ<=l)
{
ans=sqrt(2*templ/a);
}
else if(templ>l)
{
ans=sqrt(2*l/a);
templ=l;
}
if(templ<l)
{
double dis = (v*v-w*w)/2/a;
if(templ+dis<=l)
{
ans+=(v-w)/a;
ans+=(l-templ-dis)/v;
}
else
{
ans+=(sqrt(2*a*(l-templ)+w*w)-w)/a;
}
}
}
else
{
templ=v*v/2/a;
if(templ<l)
{
ans=sqrt(2*templ/a)+(l-templ)/v;
}
else if(templ>l)
{
ans=sqrt(2*l/a);
}
}
printf("%lf",ans);
return 0;
}