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 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.
 

Input

There will be at most 10 test cases. Each case begins with two integers
n and D, where n (0 <= n <= 10) is the number of rivers between A and B,
D (1 <= D <= 1000) is the distance from A to B. Each of the following
n lines describes a river with 3 integers: p, L and v (0 <=
p < D, 0 < L <= D, 1 <= v <= 100).
p
is the distance from A to the left bank of this river, L is the length of this river,
v is the speed of the boat on this river. It is guaranteed that rivers lie between A and B, and they don’t overlap. The last test case is followed by
n=D=0, which should not be processed.
 

Output

For each test case, print the case number and the expected time, rounded to 3 digits after the decimal point.

Print a blank line after the output of each test case.
 

Sample Input

1 1
0 1 2
0 1
0 0
 

Sample Output

Case 1: 1.000 Case 2: 1.000
 

Source

field=problem&key=2009+Asia+Wuhan+Regional+Contest+Hosted+by+Wuhan+University&source=1&searchmode=source">2009 Asia Wuhan Regional Contest Hosted
by Wuhan University




题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=3232



题目大意:A,B相距D,A,B间有n条河,河宽Li,每条河上有一个速度为vi的船。在河山来回行驶,每条河离A的距离为pi,如今求从A到B时间的期望。步行速度始终为1



题目分析:首先如果所有步行则期望为D,如今每遇到一条河,求过河时间的期望,等待时间的区间为(0,2*L/v)。船在每一个地方都是等可能的。所以等待的期望就是(0 + 2*L/v) / 2 = L / v,又过河还要L / v,所以总的渡河期望值为2 * L / v。所以每遇到一条河拿D减去如果步行过河的期望L再加上实际过河期望2 * L / v就可以,最后发现和p没有卵关系,真开心~

#include <cstdio>

int main()
{
int n;
double D;
int ca = 1;
while(scanf("%d %lf", &n, &D) != EOF && (n + D))
{
double p, l, v;
for(int i = 0; i < n; i++)
{
scanf("%lf %lf %lf", &p, &l, &v);
D = D - l + l * 2.0 / v;
}
printf("Case %d: %.3f\n\n", ca ++ , D);
}
}

 

HDU 3232 &amp;&amp; UVA 12230 (简单期望)的更多相关文章

  1. hdu 3232 Crossing Rivers 过河(数学期望)

    题意:你在点A,目的地是点B,A和B的距离为D.中间隔了好多条河(所有河不会重叠),每条河有3个参数(P,L,V),其中P表示距离A点的长度,L表示河的长度,V表示河里的船的速度.假设每条河中仅有1条 ...

  2. UVA 12230 - Crossing Rivers(概率)

    UVA 12230 - Crossing Rivers 题目链接 题意:给定几条河,每条河上有来回开的船,某一天出门,船位置随机,如今要求从A到B,所须要的期望时间 思路:每条河的期望,最坏就是船刚开 ...

  3. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  5. UVa 12230 && HDU 3232 Crossing Rivers (数学期望水题)

    题意:你要从A到B去上班,然而这中间有n条河,距离为d.给定这n条河离A的距离p,长度L,和船的移动速度v,求从A到B的时间的数学期望. 并且假设出门前每条船的位置是随机的,如果不是在端点,方向也是不 ...

  6. UVa 12230 - Crossing Rivers(数学期望)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. UVa 12230 (期望) Crossing Rivers

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

  8. hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)

    Problem Description   You live in a village but work in another village. You decided to follow the s ...

  9. UVA - 12230 Crossing Rivers (期望)

    Description You live in a village but work in another village. You decided to follow the straight pa ...

随机推荐

  1. JVM-java字符编码

    在JVM内部,所有的字符都是用Unicode编码的.而对于JVM所在操作系统的文件系统,可能有不同的编码类型. 由于JVM和OS文件系统所使用的编码方式不同,JVM在与操作系统进行数据交互的时候,就会 ...

  2. 添加使用session回话属性

    @SessionAttributes("nowUser") nowUser :id/userName/password public String delectMsg(int id ...

  3. 学习《零基础入门学习Python》电子书PDF+笔记+课后题及答案

    初学python入门建议学习<零基础入门学习Python>.适合新手入门,很简单很易懂.前一半将语法,后一半讲了实际的应用. Python3入门必备,小甲鱼手把手教授Python,包含电子 ...

  4. 【Django】模板系统

    目录 一.变量 二.过滤器 Filters 2. length 3. filesizeformat 4. slice 5. add 6. first.last 7. join 8. truncatec ...

  5. react基础用法二(组件渲染)

    react基础用法二(组件渲染) 如图所示组件可以是函数 格式:function 方法名(){ return <标签>内容</标签>} 渲染格式: <方法名 />  ...

  6. Python中import和from的一些事。。。

    摘自python学习手册, 用于记录. 客户端可以执行import或from语句.如果模块还没有加载,这两个语句会去搜索.编译以及执行模块文件程序.主要差别在于,import会读取整个模块,所以必须进 ...

  7. 分享到twitter,facebook,google,yahoo,linkedined,msn

    编辑器加载中... 1. 分享到twitter的代码” title=”分享到 Twitter” target=”_blank” rel=”nofollow”>Twitter 2. 分享到Face ...

  8. Objective-C 布尔类型&#160;和 class、SEL类型

    发现非常多刚開始学习的人无法区分bool和BOOL及class类型,今天闲来无事.写个博文做个区分 1. bool是C语言的布尔类型.有true和false,BOOL是Objective C 语言的布 ...

  9. 7.Emmet----HTML以及CSS的缩写请查看

  10. WinRAR 5.21 去弹窗 疑惑

    WinRAR 突然就有弹窗广告了 ,找了个方法,重新写一下安装目录下的 rarreg.key,确实有效果但是重写的和之前的完全一样啊,至少在文本中完全一样,怎么回事. 下面附上两个文件, 1.key ...