对时间的二分 奔跑的xiaodao double + 精度
2014-06-26 15:07
239 查看
题目来源:
http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2086
代码如下:
http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2086
奔跑的xiaodao | ||||||
| ||||||
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\n",b_s()*v); } return 0 ; }
相关文章推荐
- 在linux内核中获得比jiffies精度更高的时间值
- 二分求解 切绳子 (浮点数易出现精度问题)
- Codeforces 782B The Meeting Place Cannot Be Changed 二分(精度)
- hdu2289Cup(神坑题,精度+二分,以半径二分不能过,以高度为二分就过了)
- 文章标题HDU2899:Strange fuction?(二分+精度)
- TestBench中的timescale 时间延迟与时间精度
- 二分查找中的精度问题
- Navicat Oracle导入数据到mysql中的时间精度问题
- ZOJ 3717 - Balloon 简单二分+2-sat..精度恶心..
- DateTime之时间比较(CompareTo)精度问题
- poj 1064 Cable master ,二分 精度!!!
- linux内核笔记之时间管理(二) : 低精度timer
- 2009-07-03 19:48 在linux中如何获得微秒精度的时间?-转
- 二分查找时间复杂度分析
- POJ 3104 Drying (二分+精度)
- 在linux内核中获得比jiffies精度更高的时间值
- systemverilog-modelsim中运行命令,时间精度,include
- 二分查找写法总结(找元素,定区间,求精度)
- POJ2533, 最长上升子序列(贪心+二分查找时间复杂度O(nlogn))
- WaitForSingleObject等待的时间精度测试