(Expected)

Source: Internet
Author: User

Description

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 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 theexpected time to reach B from? Your walking speed is always 1.

To be more precise, for a river of LengthL, The distance of the boat (which cocould be regarded as a mathematical point) to the left bank at time 0 isuniformly chosen from interval [0,L], And the boat is equally like to be moving left or right, if it's not precisely at the river bank.

Input

There will be at most 10 test cases. Each case begins with two integersNAndD, WhereN(0N10) is the number of rivers between A and B,D(1D(1000) is the distance from A to B. Each of the followingNLines describes a river with 3 integers:P,LAndV(0P<D, 0 <LD, 1V100 ).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 followedN=D= 0, which shocould not 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 20 1 0 0
Sample output
Case 1: 1.000 Case 2: 1.000 question: give you the distance between A and B, and the information about N rivers on the way, and ask you the expected ideas from A to B: if we calculate the time for crossing the river, the fastest is L/V, and the slowest is 3l/V. The time in the period is linear, so we expect that the time is 4l/2 V = 2L/v.
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;int n;double p, l, v, d;int main() {int cas = 1;while (scanf("%d%lf", &n, &d) != EOF && n+d) {while (n--) {scanf("%lf%lf%lf", &p, &l, &v);d = d - l + l * 2 / v;}printf("Case %d: %.3lf\n\n", cas++, d);}return 0;}

 

(Expected)

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.