『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\n\n",cas,ans);
    }
}

原文地址:https://www.cnblogs.com/Fang-Hao/p/9595554.html

时间: 2024-10-03 21:54:34

『UVA 12230』Crossing Rivers (简单期望)的相关文章

HDOJ 3232 Crossing Rivers 简单概率

简单期望: 船到岸边时间的期望是 L/v 再过河的时间是L/v 所以过每条河的时间期望是2*L/v Crossing Rivers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 699    Accepted Submission(s): 361 Problem Description You live in a village bu

HDU3232 Crossing Rivers 数学期望问题

Crossing Rivers                                                                                      Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description You live in a village but work in another vil

UVA - 12230 Crossing Rivers (期望)

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

UVA - 12230 Crossing Rivers 概率期望

You live in a village but work in another village. You decided to follow the straight path between yourhouse (A) and the working place (B), but there are several rivers you need to cross. Assume B is tothe right of A, and all the rivers lie between t

Uva - 12230 Crossing Rivers (数学期望)

你住在村庄A,每天需要过很多条河到另一个村庄B上班,B在A的右边,所有的河都在A,B之间,幸运的是每条船上都有自由移动的自动船, 因此只要到达河左岸然后等船过来,在右岸下船,上船之后船的速度不变.现在问从A到B的期望时间是多少,假设在出发时船的位置都是 随机分布.人在 陆地上行走的速度为1. 根据数学期望的线性,过每条河的时间为L/v(到河边船刚好开)到3L/v(到河边船刚好开走)的均匀分布,因此期望过河时间为 (L+3L/v)/2=(2*L/v) 加上 D-sum(L) . 1 #includ

UVa12230 - Crossing Rivers (数学期望)

题意:给你A和B的距离,以及途中n条河的信息,问你从A到B的期望 思路:我们单纯算过河时间的话,最快的是l/v,最慢的可能是3l/v,期间的时间是线性的,所以期望就是4l/2v=2l/v #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> int main() { int n; double p,l,v,d; int cas=1; while(scanf(&quo

uva 12230 - Crossing Rivers(求数学期望)

利用了数学期望的线性性质:有线个随机变量之和的数学期望的关于每个随机变量的期望之和: 由于过每条河的时间为L / V和3L / V的均匀分布,因此期望过河时间为2L / V. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n;double d; int main() { int kase=0; while(scanf("%d%lf",&a

UVA 12230 - Crossing Rivers(概率)

UVA 12230 - Crossing Rivers 题目链接 题意:给定几条河,每条河上有来回开的船,某一天出门,船位置随机,现在要求从A到B,所需要的期望时间 思路:每条河的期望,最坏就是船刚开走3L/V,最好就是直接上船L/V,期望为4L/V/2 = 2L/V,然后在算上陆地上的时间,就是答案 代码: #include <stdio.h> #include <string.h> int n; double d, p, l, v; int main() { int cas =

HDU 3232 &amp;amp;&amp;amp; UVA 12230 (简单期望)

Crossing Rivers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 738    Accepted Submission(s): 387 Problem Description You live in a village but work in another village. You decided to follow t