UVa 12230 (期望) Crossing Rivers

题意:

从A到B两地相距D,之间有n段河,每段河有一条小船,船的位置以及方向随机分布,速度大小不变。每段河之间是陆地,而且在陆地上行走的速度为1.求从A到B的时间期望。

分析:

我们只要分析每段河的期望即可。设河的长度为L,船速为v。过河最短时间为刚好搭上从左向右开的小船L/v;最长时间为刚好没搭上从左向右开的小船,所以要等小船开到对岸再折返回来再到对岸,时间为3L/v,因为是均匀分布,所以期望为2L/v,最后再加上陆地上行走的时间就是答案。

 1 #include <cstdio>
 2
 3 int main()
 4 {
 5     int n, D, kase = 0;
 6     while(scanf("%d%d", &n, &D) == 2)
 7     {
 8         if(n == 0 && D == 0) break;
 9         int L, v, p;
10         int sumL = 0;
11         double ans = 0.0;
12         for(int i = 0; i < n; ++i)
13         {
14             scanf("%d%d%d", &p, &L, &v);
15             sumL += L;
16             ans += 2.0 * L / v;
17         }
18         ans += D - sumL;
19
20         printf("Case %d: %.3f\n\n", ++kase, ans);
21     }
22
23     return 0;
24 }

代码君

时间: 2024-12-16 09:57:38

UVa 12230 (期望) Crossing Rivers的相关文章

『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 river

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 =

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

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

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

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(数学期望)

链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3382 题意: 你住在村庄A,每天需要过很多条河到另一个村庄B上班.B在A的右边,所有的河都在中间.幸运的是,每条河上都有匀速移动的自动船,因此每当到达一条河的左岸时,只需等船过来,载着你过河,然后在右岸下船.你很瘦,因此上船之后船速不变.日复一日,年复一年,你问自己:从A到B,平均