# Ultraviolet A 12230 crossing rivers (mathematical expectation)

Source: Internet
Author: User

You want to go to work from A to B. However, there are n rivers in the middle, and the distance is D. Given the distance between the N rivers and A, P, L, and the moving speed of the ship V, the mathematical expectation of the time from A to B is obtained.

And assume that the positions of each ship are random before going out. If it is not at the endpoint, the direction is also not fixed. If you walk at a speed of 1 on land, input to ensure that the river is before AB, and does not overlap.

Analysis: it seems that this question does not exist... How can we solve this problem? It's so messy, so complicated...

But when I think about time expectation, isn't the time in the area where the river is crossed fixed? Just find the mathematical expectation of the time when the river is crossed, and use the linearity of the mathematical expectation to add up.

If you think about it like this, it will not be messy. How can you find the time of every river? The problem is that all ships are random and can be considered as equal probability, the shortest time for crossing the river is L/V, and the boat just arrived by the river,

The longest time is 3 * L/V, that is, when he just arrived at the river, the ship had just arrived, and finally the time on land was OK.

The Code is as follows:

`# Include <iostream> # include <cstring> # include <vector> # include <algorithm> # include <cstdio> using namespace STD; int main () {int N, D, kase = 0; while (scanf ("% d", & N, & D) {If (! D &&! N) break; double ans = (double) D; For (INT I = 0; I <n; ++ I) {Double P, L, V; scanf ("% lf", & P, & L, & V); ans = ANS-L + 2 * L/V; // because the speed on land is 1, you do not need to remove} printf ("case % d: %. 3lf \ n ", ++ Kase, ANS);} return 0 ;}`

Ultraviolet A 12230 crossing rivers (mathematical expectation)

Related Keywords:

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.