# 对时间的二分 奔跑的xiaodao double + 精度

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

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

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

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

Input

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

Output

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\n",b_s()*v);
}
return 0 ;
}

• 0
点赞
• 0
评论
• 0
收藏
• 扫一扫，分享海报

01-05
12-23 8616

05-01 203
04-02 30
04-23 390
03-21 888
02-17 47
07-25 1085
02-19 200
04-02 1036
05-01 47
06-19 476
01-08 56