HDU3232 Crossing Rivers Mathematical expectation problem

Source: Internet
Author: User
Tags time 0

Crossing Rivers

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)

Problem Descriptionyou 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 river, just wait for the boat and then go with it. You ' re so slim this carrying you does don't change the speed of any boat.

Days and days after, you came up with the following question:assume each boat are independently placed at random at time 0 , what is the expectedTime to reach B from A? Your walking speed was 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 is uniformly chosenFrom interval [0, L], and the boat is equally like to being moving left or right, if it's not precisely on the river bank.


Inputthere'll is at the most test cases. Each case begins with a integers Nand D, where N(0 <= N<=) is the number of rivers between A and B, D(1 <= D<=) is the distance from A to B. Each of the following NLines describes a river with 3 integers: p, Land v(0 <= P< D, 0 < L<= D, 1 <= v<= 100). Pis the distance from A to the left bank of this river, LIs the length of this river, vIs the speed of the boat on the the. 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 not being processed.


Outputfor 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 INPUT1 10 1 20 10 0


Sample outputcase 1:1.000case 2:1The main idea : the distance between A and b two points is D, and there are N rivers between A and B, and there is an automatic ship on each river. The width of the ship is L, when the boat is regarded as a point, its position at the No. 0 moment is arbitrary, and the possibility of paddling to the cross-strait is the same. It is known that the speed of the walk is 1, the ship's speed is V, and the distance of each river from a point is P, and the time it takes to get a to B is how much.
Analysis: It is not difficult to draw from the test instructions, the ship in 0 time on the river position to meet the uniform distribution, then by the uniform distribution we know its mathematical expectation e = L/2. The probability of a boat going to the left bank is equal to 1/2 of the right bank, because the man only crosses the boat to the left bank and then to the right bank to cross the River. So when the boat left the shore, it reached the desired time on the Left Bank T1 = L/2 * /V; When the boat is on the right bank, the desired time of the left bank that it reaches T2 = (L/2 + L) */V; the last time from the left bank to the right bank is T3 = l/v; The total expected time to cross the river is T = T1 + T2 + T3 = 2l/v;
#include <stdio.h>intMain () {intn, I, CAS =0, D, P, L, V;  while(~SCANF ("%d%d", &n,&d), n+d) {DoubleAns = d*1.0;  for(i =0; I < n; i++) {scanf ("%d%d%d", &p, &l, &v); Ans-= l;//minus the time it took for the river.Ans + =2.0*l/v;//plus time across the river} printf ("Case %d:%.3lf\n\n",++cas, ans); }    return 0;}

HDU3232 Crossing Rivers Mathematical expectation problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.