This question is very good and I like it very much!
This question means that two people will encounter a city by train, but the time taken by train to a city is not certain. The time range from the first person to the station is [T1, t2], the time range for the second person to arrive at the station is [S1, S2], while the time for the car to stay at the station is W. What is the probability of a person meeting at the station?
In fact, I think there are some problems with the results of this question. In fact, the problem is solved within the range of [T1, T2], but the train has left, but according to the actual meaning, it should not arrive at T2, will the T2 + W train go? There are some problems, but we mainly want to learn some ideas!
An amazing SolutionCodeAfter conquering me, the code is short, and the efficiency and ability to solve the problem by category are on the paper. This is why people with good brains are able to save themselves from difficulties because their ideas are very rational, the steps for solving the problem have long been fixed.
The topic category is very good. I can understand it after reading it, but I think it is very difficult to estimate it. This is the difference between being smart and not smart. I have done more and less questions, paste the Code:
# Include <stdio. h> # include <string. h >#include <iostream >#include <string> using namespace STD; double T1, T2, S1, S2, W; double height, width; double getarea (double W) {double Tx = S2-W; double BX = S1-W; double ly = t1 + W; double ry = T2 + W; bool onleft = (ly <= S2 & LY> = S1); bool onright = (RY <= S2 & ry> = S1 ); bool ontop = (TX <= t2 & TX> = T1); bool onbottom = (BX <= t2 & BX> = T1); If (onleft & Ontop) {return (TX-t1) * (S2-ly) * 0.5;} If (onleft & onright) {return (TX-t1) * (S2-ly)-(TX-t2) * (S2-ry) * 0.5; // return (S2-Ly + S2-ry) * width * 0.5 ;} if (ontop & onbottom) {return (TX-t1) * (S2-ly)-(S1-ly) * (bx-t1) * 0.5; // return (bx-t1 + Tx-t1) * height * 0.5;} If (onbottom & onright) {return (height * width)-(T2-bx) * (ry-S1) * 0.5;} return ly <= S1? Height * width: 0;} int main () {int t; scanf ("% d", & T); For (INT case = 1; Case <= T; case ++) {scanf ("% lf", & T1, & T2, & S1, & S2, & W ); width = (T2-t1); Height = (S2-S1); double ans1 = getarea (w); double ans2 = getarea (-1 * w ); // cout <ans2 <Endl; // cout <ans1 <Endl; printf ("case # % d: %. 8lf \ n ", Case, (ans2-ans1)/(width * Height);} // system (" pause "); Return 0 ;}