You live in a village but work in another village. You decided to follow the straight path between your
House (A) and the Working place (B), but there is several rivers you need to cross. Assume B is to
The right of A, and all the rivers lie between them.
Fortunately, there is one "automatic" boat moving smoothly in each river. When you arrive the
Left bank of a, just wait for the boat and then go with it. You ' re so slim this carrying you does not
Change the speed of any boat.
Days and days after, you came up with the following question:assume each boat is independently
Placed at random at time 0, what's the expected time to reach B from A? Your Walking speed is
Always 1.
To is more precise, for a river of length L, the distance of the boat (which could is regarded as a
Mathematical point) to the left bank at time 0 was uniformly chosen from interval [0, L], and the boat
Is equally like to being moving left or right, if it's not precisely on the river bank.
Input
There'll is at the most test cases. Each case begins with integers n and D, where N (0≤n≤10)
Is the number of rivers between A and B, D (1≤d≤1000) are the distance from A to B. Each of the
Following n lines describes a river with 3 integers:p, L and V (0≤p < D, 0 < L≤d, 1≤v≤100). P
is the distance from A to the left bank of the This river, and L is the length of the
Boat on the river. It's guaranteed that rivers lie between A and B, and they don ' t overlap. The last
Test case was followed by n = D = 0, which should wasn't be processed.
Output
For each test case, print the case number and the expected time, rounded to 3 digits after the decimal
Point.
Print a blank line after the output of each test case.
Sample Input
1 1
0 1 2
0 1
0 0
Sample Output
Case 1:1
Case 2:1
Test Instructions : There is a person to go to the company every day to work, every time through the N River, home and the company's distance is D, the default on the land speed of 1, give information about the N river, including the starting coordinates p, width l, and the speed of the boat. The boat will be back and forth on both sides of the river, where people reach the bank, where the ship's position is random (including direction). Ask people to reach the desired time that the company needs.
Puzzle: Because there is a direction we simply calculate the river time, the fastest is l/v, the slowest may be 3l/v, period of time is linear, so the expectation is 4l/2v=2l/v, plus the land unit time can be
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd; typedefLong Longll;Const intn= -+Ten;intMain () {intCAS =1, N; DoubleD, P, L, V; while(~SCANF ("%D%LF",&n,&d)) {if(n = =0&& D = =0) Break; for(inti =0; i < n; i++) {scanf ("%LF%LF%LF",&p,&l,&v); D= D-l + L *2/v; } printf ("Case %d:%.3f\n\n", cas++, D); } return 0;}Code
UVA-12230 Crossing Rivers Probability expectation