Uva-12230 Crossing Rivers (mathematical expectation)

Source: Internet
Author: User

You live in village A, you need a lot of river to another village B to work every day, B on the right side of a, all the river is between a A and a, fortunately, each ship has a free-moving automatic boat,

So just reach the left bank of the river and wait for the boat to come, disembark on the right bank, the ship's speed unchanged after the boat. Now ask what the expected time from A to B is, assuming that the ship's position at the departure is

Randomly distributed. The speed at which people walk on land is 1.

According to the mathematical expectation of linearity, the time for each river is l/v (to the river side of the boat just open) to the 3l/v (to the river side of the boat just off) evenly distributed, so expect to cross the river Time for (l+3l/v)/2= (2*l/v) plus d-sum (L).

1#include <cstdio>2#include <cstring>3 intMain ()4 {5     intn,d,p,l,v,s,j=1;6     Doublesum;7      while(~SCANF ("%d%d",&n,&d))8     {9         if(n==0&&d==0) Break;Tensum=0; Ones=0; A          for(intI=0; i<n;i++) -         { -scanf"%d%d%d",&p,&l,&v); thesum+=2.0*l/v; -s+=l; -         } -printf"Case %d:%.3lf\n\n", j++,sum+ (ds)); +     } -     return 0; +}

Uva-12230 Crossing Rivers (mathematical expectation)

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.