Land oj 1609 - Han Move (模拟)

来源:互联网 发布:苹果mac复制粘贴全选 编辑:程序博客网 时间:2024/04/30 23:23
Problem 1609 - Han Move
Time Limit: 1000MS   Memory Limit: 65536KB   
Total Submit: 619  Accepted: 161  Special Judge: No
Description
Cyy and Fzz are Han Move lovers. One day, they gather together to run. They choose a circular track whose length is L m. Cyy’s speed is A m/s and Fzz’s speed is B m/s. They may choose the direction separately, i.e. they may start with the same direction or different direction. As they’re crazy, they’ll run infinitely. Gatevin, their friend, wonders the possibility of their distance is less than D m. The distance is defined as the distance on the track. The possibility is defined as the ratio between the sum of time satisfying the condition and the total time.
Input
The input file consists of multiple test cases ( around 1000000 ).
Each test case consists of 5 integers L, A, B, D, Dir in a line. The meanings of L, A, B, D are as described above. Dir means whether they are in the same direction. Dir = 1 means they are in the same direction, while Dir = 0 means they are in the opposite direction. ( 1 <= L, A, B, D <= 32768, 0 <= Dir <= 1 )
Output
For each test case, output the possibility rounded to 6 demical places in a line.
Sample Input
1200 200 400 300 0
1200 200 400 300 1
Sample Output
0.500000
0.500000
Hint

 Please pay attention to the speed of I/O.

//题意:

输入l,a,b,d,dd,l表示操场的长度,a表示第一个人的速度,b表示第二个人的速度,d表示追踪距离的最大值(两人之间的距离<=d时即为追踪)

dd表示方向,0表示他俩反向,1表示他俩同向。

两个人出发点在操场上同一点沿着操场一直无限的跑圈,问他们之间的距离为追踪距离的时间与他们跑的总时间的比值。

//思路:

因为他俩是在无限的跑圈,速度不变,所以只用求出他俩共同跑完一圈的比值就是最终的比值了。

首先得明确一下他俩在一圈内会有两段追踪距离的时间(刚开始时和第二次即将相遇时),不理解的可以画个圈模拟一下就明白了。

其次求比值就得分情况了:

1、他俩同向:他们的共同速度为sum=fabs(a-b),所以他们跑一圈的总时间为tt=l/sum;他们在追踪的时间为t=d/sum*2(2为他们在一圈内会有两次相遇)。

2、他俩反向:他们的共同速度为sum=a+b,所以他们跑一圈的总时间为tt=l/sum;他们在追踪的时间为t=d/sum*2(2为他们在一圈内会有两次相遇)。

然后他们的比值即为ans=t/tt;

当然这只是两个大的方面,还有一些特殊情况得特殊判断,所以得加一些特判。(具体看代码)

#include<stdio.h>#include<string.h>#include<math.h>#include<map>#include<queue>#include<stack>#include<set>#include<algorithm>#include<iostream>#define INF 0x3f3f3f3f#define ull unsigned long long#define ll long long#define IN __int64#define N 100010#define M 1000000007using namespace std;int main(){double l,a,b,d;int dd;while(scanf("%lf%lf%lf%lf%d",&l,&a,&b,&d,&dd)!=EOF){int sum;double ans,t,tt;if(d>=l){printf("1.000000\n");continue;}if(a==b&&dd==1&&d==0){printf("1.000000\n");continue;}if(d==0){printf("0.000000\n");continue;}if(dd==0){sum=a+b;tt=l*1.0/sum;t=2*d*1.0/sum;ans=t/tt;}else{sum=fabs(a-b);if(sum==0){printf("1.000000\n");continue;}tt=l*1.0/sum;t=2*d*1.0/sum;ans=t/tt;}if(ans>=1)printf("1.000000\n");elseprintf("%.6lf\n",ans);}return 0;} 


 

0 0
原创粉丝点击