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. DECLARE CURSOR (Transact-SQL)

    Defines the attributes of a Transact-SQL server cursor, such as its scrolling behavior and the query ...

  2. oracle job有定时执行功能

    oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务.   oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务. 一.查询系统中的 ...

  3. IOC DI 专题

    IoC:Inversion of Control,控制反转DI:Dependency Injection,依赖注入 要理解上面两个概念,就必须搞清楚如下的问题: 参与者都有谁?依赖:谁依赖于谁?为什么 ...

  4. MySQL Server 5.5.44免安装版配置详解

    转载地址:http://wenku.baidu.com/view/2a8bfe6a25c52cc58bd6beff.html### 一 下载MySQL http://dev.mysql.com/dow ...

  5. 随机模拟的基本思想和常用采样方法(sampling)

    转自:http://blog.csdn.net/xianlingmao/article/details/7768833 引入 我们会遇到很多问题无法用分析的方法来求得精确解,例如由于式子特别,真的解不 ...

  6. 商业模式(三):P2P网贷平台,毛利润测算

    之前谈到P2P网贷平台,主要的收入就是"息差".        一直以来,想详细写点P2P平台的收益到底如何的,奈何自己感觉收入上的点不算多,对财务这种核心机密了解的也不多,一直没 ...

  7. C# async/await异步编程深入理解

    异步函数简介 一般指 async 修饰符声明得.可包含await表达式得方法或匿名函数. 声明方式 异步方法的声明语法与其他方法完全一样, 只是需要包含 async 关键字.async可以出现在返回值 ...

  8. HDU——T 1251 统计难题

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 Time Limit: 4000/2000 MS (Java/Others)    Memory Limi ...

  9. js02---字符串

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  10. Kinect 开发 —— 近距离探测

    如何将Kinect设备作为一个近距离探测传感器.为了演示这一点,我们处理的场景可能在以前看到过.就是某一个人是否站在Kinect前面,在Kinect前面移动的是人还是什么其他的物体.当我们设置的触发器 ...