『UVA 12230』Crossing Rivers (简单期望)
Posted fang-hao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了『UVA 12230』Crossing Rivers (简单期望)相关的知识,希望对你有一定的参考价值。
题目描述
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
",cas,ans);
}
}
以上是关于『UVA 12230』Crossing Rivers (简单期望)的主要内容,如果未能解决你的问题,请参考以下文章
Uva12230Crossing Rivers (数学期望)
『UVA 12230』Crossing Rivers (简单期望)