You want to go to work from A to B. However, there are n rivers in the middle, and the distance is D. Given the distance between the N rivers and A, P, L, and the moving speed of the ship V, the mathematical expectation of the time from A to B is obtained.
And assume that the positions of each ship are random before going out. If it is not at the endpoint, the direction is also not fixed. If you walk at a speed of 1 on land, input to ensure that the river is before AB, and does not overlap.
Analysis: it seems that this question does not exist... How can we solve this problem? It's so messy, so complicated...
But when I think about time expectation, isn't the time in the area where the river is crossed fixed? Just find the mathematical expectation of the time when the river is crossed, and use the linearity of the mathematical expectation to add up.
If you think about it like this, it will not be messy. How can you find the time of every river? The problem is that all ships are random and can be considered as equal probability, the shortest time for crossing the river is L/V, and the boat just arrived by the river,
The longest time is 3 * L/V, that is, when he just arrived at the river, the ship had just arrived, and finally the time on land was OK.
The Code is as follows:
# Include <iostream> # include <cstring> # include <vector> # include <algorithm> # include <cstdio> using namespace STD; int main () {int N, D, kase = 0; while (scanf ("% d", & N, & D) {If (! D &&! N) break; double ans = (double) D; For (INT I = 0; I <n; ++ I) {Double P, L, V; scanf ("% lf", & P, & L, & V); ans = ANS-L + 2 * L/V; // because the speed on land is 1, you do not need to remove} printf ("case % d: %. 3lf \ n ", ++ Kase, ANS);} return 0 ;}
Ultraviolet A 12230 crossing rivers (mathematical expectation)