1. 程式人生 > >『UVA 12230』Crossing Rivers (簡單期望)

『UVA 12230』Crossing Rivers (簡單期望)

方向 一道 can 最快 use you uva tel 都是

題目鏈接戳這裏

題目描述

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 the expected time to reach B from A? Your walking speed is
always 1.
To be more precise, for a river of length L, the distance of the boat (which could be regarded as a
mathematical point) to the left bank at time 0 is uniformly 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.


中文翻譯

現在從A到B的長度為\(D\),並且A到B之間有\(n\)條河,每條河的長度為\(L_i\),每條河上又一條船以\(V_i\)來回運行,在0時刻人出發,並且每艘船在0時刻會隨機出現在河上的一個位置,方向隨機。人在陸地上行走的速度恒為\(1\),求從A到達B的時間的期望值。



解題思路

乍一看沒啥思路,像一道概率\(dp\),其實仔細想想,這是一道假題。

首先,渡每條河的時間期望都是獨立的,互不影響,這是最假的一點。其次,我們發現度過一條河的最快時間是\(\frac{L_i}{V_i}\),最慢時間是\(\frac{3*L_i}{V_i}\),我們發現,在\([\frac{L_i}{V_i},\frac{3*L_i}{V_i}]\)之間,每個值取到的概率是相同的,那平均下來就是\(\frac{2*L_i}{V_i}\),然後就完了qwq



代碼

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    int n,d,cas=0;
    while(~scanf("%d%d",&n,&d)){
        if(n==0&&d==0)return 0;
        double ans=0;
        cas++;
        for(register int i=1,p,l,v;i<=n;i++){
            scanf("%d%d%d",&p,&l,&v);
            d-=l;
            ans+=l*2.0/v;
        }
        ans+=d;
        printf("Case %d: %.3lf\n\n",cas,ans);
    }
}

『UVA 12230』Crossing Rivers (簡單期望)