zoukankan      html  css  js  c++  java
  • 对时间的二分 奔跑的xiaodao double + 精度

    题目来源:

    http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2086

    奔跑的xiaodao
    Time Limit: 4000 MS Memory Limit: 65536 K
    Total Submit: 57(12 users) Total Accepted: 14(5 users) Rating:  Special Judge: Yes
    Description

    某天,DS同学和他的妹子终于要见面了。DS在遥远的西藏,妹子在北京,中间隔着一条长长的川藏公路。DS和妹子都在这条公路上相向而行,因为过于思念对方,DS派出了xiaodao作为自己的情书信使。

    DS和妹子相向而行,速度为 v1 , v2 m/s 尽职尽责的xiaodao同学以 v m/s 的速度奔跑,他一开始拿着DS的信向妹子的方向狂奔,遇到妹子之后毫不停歇,拿着妹子的书信继续以 v 的速度向DS奔跑,周而复始,一直到DS和妹子相遇为止。好辛劳的xiaodao

    但是DS是个胖子,妹子是女生,大家都体力不太行。已知DS奔跑 T1 s 之后就要休息 Wait1 s ,妹子奔跑 T2 s 之后就要休息 Wait2 s 。而xiaodao是不会休息的!经过计算,DS和妹子的初始距离为 L 

    xiaodao想问你,当DS和妹子终于相遇的时候,xiaodao这时候已经奔跑了多少 m 的距离。

    Input

    第一行一个整数 T  代表数据组数,以下 T 组数据。

    每组数据包含 8 个实数 分别代表 v1 , v2 , v , T1 , T2 , Wait1 , Wait2 , L

    1 <= v1 , v2 <= 100 , v1 < v <= 100 , 1 <= T1 , T2 <= 1000 , 0 <= Wait1 , Wait2 <= 1000 . 1 <= L <= 10000 .

    Output

    对于每组数据输出一个实数 S 代表 xiaodao 奔跑的距离。
    如果标程给出的答案是 Ans  只要 | Ans - S | < 1e-5 你就会得到 Accepted

    Sample Input
    1
    1.00 1.00 2.00 1.00 1.00 0.00 0.00 2.00
    
    Sample Output
    2.000000000

    代码如下:

    #include <iostream>
    #include <algorithm>
    #include <stdlib.h>
    #include <stack>
    #include <iostream>
    #include <stdio.h>
    #include <string>
    #include <string.h>
    #include <algorithm>
    #include <stdlib.h>
    #include <vector>
    #include <set>
    #include <math.h>
    #include <cmath>
    #include <map>
    #include <stack>
    #include <queue>
    using namespace std ;
    
    typedef long long LL ;
    const double EPS=1e-8;
    double v1,v2,v,t1,t2,w1,w2,L;
    
    bool judge(double time)
    {
        double t11= (int) (time/(t1+w1) );
        double len1=t11* t1*v1;
        if(time - t11*(t1+w1)  >=t1)
            len1+=t1*v1;
        else
            len1+= (time - t11*(t1+w1) )*v1;
        double t22=(int)(time/(t2+w2) );
        double len2= t22*t2*v2;
        if( time-t22*(t2+w2) >=t2 )
            len2+=t2*v2;
        else
            len2+= (time-t22*(t2+w2) ) *v2;
        if( len1 + len2 -L > EPS  || fabs(len1+len2-L) < EPS )
            return 1;
        return 0;
    }
    double b_s()
    {
        double left,right,mid;
        left=0.0;
        right=1e8;
        while(right -left >EPS)
        {
            mid=(left + right)*0.5;
            if( judge(mid)  )
                right=mid;
            else left=mid;
        }
        return (right + left) *0.5;
    }
    int  main(){
        int t;
        cin>>t;
        while(t--)
        {
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&v1,&v2,&v,&t1,&t2,&w1,&w2,&L);
            printf("%.6lf
    ",b_s()*v);
        }
         return 0 ;
    }
  • 相关阅读:
    【转载】Python tips: 什么是*args和**kwargs?
    Python关于File学习过程
    tensorflow训练中出现nan
    axis调用Web服务报axis unexpected wrapper element{XXXX}XXX错误的解决
    微信小程序windowHeight的值在ios和android平台不一致问题解决办法
    微信小程序scroll-view滚动一次多次触发的问题解决方案
    微信小程序自定义TabBar
    微信小程序页面列表与详情页跳转的正确姿势
    Spring动态获取已注入的对象的方法
    MAVEN项目不扫描mybatis的mapper.xml问题
  • 原文地址:https://www.cnblogs.com/zn505119020/p/3637858.html
Copyright © 2011-2022 走看看