Problem 1609 - Han Move
Time Limit: 1000MS
Memory Limit: 65536KB
Total Submit: 613 Accepted: 158 Special Judge: No
Total Submit: 613 Accepted: 158 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 )
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
1200 200 400 300 1
Sample Output
0.500000
0.500000
0.500000
Hint
Please pay attention to the speed of I/O.
考虑从开始起跑到两人第一次碰面的这一段时间内,同向时速度相减求总时间,反向时速度相加和求总时间,注意当d>=l/2时以及同向速度相同时是一直都符合条件的
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int L,a,b,d,dir;
while(scanf("%d%d%d%d%d",&L,&a,&b,&d,&dir)!=EOF)
{
if(!dir)
{
if(d>=(L*1.0/2))
{
printf("1.000000\n");
continue;
}
double sum_time=L*1.0/((a+b)*1.0);
double d_time=d*1.0/((a+b)*1.0)*2;
printf("%.6lf\n",d_time/sum_time);
}
else
{
if(a==b)
{
printf("1.000000\n");
continue;
}
if(d>=(L*1.0/2))
{
printf("1.000000\n");
continue;
}
if(b>a)
{
int t=a;
a=b;
b=t;
}
double sum_time=L*1.0/((a-b)*1.0);
double d_time=d*1.0/((a-b)*1.0)*2;
printf("%.6lf\n",d_time/sum_time);
}
}
return 0;
}