Topic Connection: UVA 11722-joining with Friend
You and your friends take the train, and will pass a city. Given that two people may arrive at City A, the train will stop W. Ask the probability that two people can meet.
Problem-solving ideas: y = x + W and y = x-w the area around the given time divided by the total area of time, that is, when the area is to be processed by the situation.
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;intT1, T2, S1, S2, W;DoubleSumDoubleSolve (intK) {DoubleRET =0;if(S2 > t2 + k && S1 > T1 + k) {Doubler = max (T2 + k-s1,0); RET = Sum-r * R/2; }Else if(S2 > t2 + k) {DoubleR =2* S2-T1-T2-2K RET = R * (T2-T1)/2; }Else if(S1 > t1 + k) {Doubler = s2 + S1-2K2* T1; RET = R * (S2-S1)/2; }Else{Doubler = Max (S2-k-T1,0); RET = R * R/2; }if(K <0) ret = Sum-ret;returnRET;}intMain () {intCAsscanf("%d", &cas); for(intKcas =1; Kcas <= cas; kcas++) {scanf("%d%d%d%d%d", &t1, &t2, &s1, &s2, &w); sum =1.0* (T2-T1) * (S2-S1);Doubleans = Solve (W) + Solve (-W);printf("Case #%d:%.8lf\n", Kcas,1-Ans/sum); }return 0;}
UVA 11722-joining with Friend (probability)