HDOJ 3232 simple probability of Crossing Rivers,

Source: Internet
Author: User
Tags time 0

HDOJ 3232 simple probability of Crossing Rivers,


Simple expectation:

The expected time for the ship to the shore is that the time for the ship to cross the river is L/v.

Therefore, the expected time for crossing each river is 2 * L/v.

Crossing Rivers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 699 Accepted Submission (s): 361


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 are 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, then go with it. you're so slim that 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 is ExpectedTime to reach B from? Your walking speed is always 1.

To be more precise, for a river of length L, the distance of the boat (which cocould be 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 be moving left or right, if it's not precisely at the river bank.
InputThere will be at most 10 test cases. Each case begins with two integers NAnd D, Where N(0 <= N<= 10) is the number of rivers between A and B, D(1 <= D<= 1000) 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 this river. It is guaranteed that rivers lie between A and B, and they don't overlap. The last test case is followed N = D = 0, Which shoshould not be 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 Input
1 10 1 20 10 0
 
Sample Output
Case 1: 1.000Case 2: 1.000
 
Source2009 Asia Wuhan Regional Contest Hosted by Wuhan University

/*************************************** * ******** Author: CKbossCreated Time:, Thursday, January 29, 2015 File Name: UVA12230.cpp *************************************** * ********/# include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <string> # include <cmath> # include <cstdlib> # include <vector> # include <queue> # include <set> # include <map> using namespace std; int n, d; struct Riv Er {int p, l, v;} ri [20]; int main () {// freopen ("in.txt", "r", stdin ); // freopen ("out.txt", "w", stdout); int cas = 1; while (scanf ("% d", & n, & d )! = EOF) {if (n = 0 & d = 0) break; double ans1 = 0.0; double sum = 0.0; for (int I = 0; I <n; I ++) {int a, B, c; scanf ("% d", & a, & B, & c ); ri [I] = (River) {a, B, c}; ans1 + = 2. * B/c; sum + = B;} ans1 + = (d-sum); printf ("Case % d: %. 3lf \ n ", cas ++, ans1); putchar (10);} return 0 ;}



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.