题解 | #游游开车出游#

游游开车出游

https://www.nowcoder.com/practice/667369e08b2f498c89a935df0af921b3

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
     double v0,x,y;
    cin>>v0>>x>>y;

    double t0 = (-v0*x + sqrt(x*x*x*y))/(x*x);
    double total = t0+ y/(v0+t0*x);
   
    if(v0!=0 && t0<0){
        total= y/v0;
    }
    // cout<<t0<<endl;
    cout<<setprecision(10)<<total;
}
// 64 位输出请用 printf("%lld")
//  t=t1+ y/(v0+t1*x)

t0为加油时间,则

最短时间T=t0+ y/(v0+x*t0)

求导可知T’ = 1 - x*y/(v0+x*t0)

因为x,y大于0,v0大于等于0,所以T>0的最小值点应为T'=0

即(x*t0+v0)^2=xy

t0=(-v0*x + sqrt(x*x*x*y))/(x*x),但由于t0有可能小于0,此时则为不加油直接出发用时最短

全部评论

相关推荐

01-07 07:54
已编辑
门头沟学院 前端工程师
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务