You be going from Dhaka to Chittagong by train and your came to know one of the your old friends was going from city Chittagong To Sylhet. You also know that both the trains would have a stoppage at junction Akhaura at almost same time. You wanted to see your friend there. But the system of the country are not good. The times of reaching to Akhaura for both trains is not fixed. In fact your train can reach in any time within the interval [T1, T2] with equal probability. The other one would reach in any time within the interval [S1, S2] with equal probability. Each of the trains would stop for W minutes after reaching the junction. You can only see your friend, if in some time both of the trains are present in the station. Find the probability that's can see your friend. |
Input |
The first line of input would denote the number of cases T (T < a). Each of the following T -line would contain 5 integers t1, t2, S1, S2, W (360≤t1 < T2 < 1080, 360≤S1 < S2 < 1≤w≤90). All inputs T1, T2, s1, S2 and W is given in minutes and T1, T2, S1, s2< /c10> is minutes since midnight00:00. |
Output |
For each test case, print one line of output in the format "case#k: P" Here are the case number and p is the probability of seeing your friend. Up-to- 1e-6 error in your output would be acceptable. |
Sample Input |
Output for Sample Input |
2 1000 1040 1000) 1040 20 720 750 730) 760 16 |
Case #1:0.75000000 Case #2:0.67111111 |
Problem Solving Ideas:
Test instructions: You and your friends have to take the train, in order to meet in a city, you will be in the time zone [T1, T2] at any moment in the same probability density to reach, you
Friends will arrive at any moment in the time zone [S1, S2] at the same probability density, and your train will stay at the station for W seconds,
Only when the train is in city a at the same time will meet, ask you the probability of this thing
Idea: Construct the density into a rectangle and then solve the size of the matrix area of y = x + (-) B, and discuss the situation.
Program code:
#include <cstdio>using namespacestd;Doublet1,t2,s1,s2;DoubleCalDoubleW) { Doublex1=s1-w,x2=s2-w,y1=t1+w,y2=t2+W; if(Y1>=S2)return 0; if(Y2<=S1)return(T2-T1) * (s2-S1); BOOLL= (y1>=s1&&y1<=S2); BOOLR= (y2>=s1&&y2<=S2); BOOLU= (x2>=t1&&x2<=T2); BOOLD= (x1>=t1&&x1<=T2); if(L&&u)return(X2-T1) * (s2-y1) *0.5; if(L&&r)return(s2-y1+s2-y2) * (T2-T1) *0.5; if(D&&u)return(X2-T1+X1-T1) * (S2-S1) *0.5; if(D&&r)return(T2-T1) * (S2-S1)-(t2-x1) * (Y2-S1) *0.5;}intMain () {intCase=0, T; DoubleW; scanf ("%d",&t); while(t--) {scanf ("%LF%LF%LF%LF%LF",&t1,&t2,&s1,&s2,&W); printf ("Case #%d:%.7lf\n", ++case, (Cal (-W)-cal (W))/(T2-T1)/(s2-s1)); } return 0;}
View Code
Mathematical concept--a geometrical approximate type