---restore content starts---
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471
Test instructions, two trains, will stay at the same site for the time period of [t1,t2],[s1,s2], and ask the probability that two trains will meet at this site.
Idea, enumerate each case, draw out the intersection of the two trains, and then ask the probabilities in this interval
#include"iostream"#include"Cstdio"#include"Cmath"using namespacestd;intCA;DoubleT1,t2,s1,s2,w,ans;DoubleCaculate (Doubleb) { inty1=t1+b,y2=t2+b; if(Y2<S1)return 0; if(y1<S1) { if(Y2<S2)return 0.5* (Y2-S1) * (y2-S1); Else return 0.5* (S2-S1) * (2*y2-s1-S2); } if(y1<S2) { if(Y2<S2)return 0.5* (T2-T1) * (y1-s1+y2-S1); Else return(T2-T1) * (S2-S1)-0.5* (s2-y1) * (s2-y1); } return(T2-T1) * (s2-s1);}voidInit () {scanf ("%LF%LF%LF%LF%LF",&t1,&t2,&s1,&s2,&w);}voidWork () {ans= (Caculate (w)-caculate (-W))/((T2-T1) * (s2-s1));}voidPrint () {printf ("Case #%d:%.8f\n", ca++, ans);}intMain () {intT; CA=1; CIN>>u; while(t--) {Init (); Work (); Print (); } return 0;}View Code
---restore content ends---
Sixth week of training the concept and methods of mathematics UVA 11722 Geometrical overview