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 , what is the expected time to reach B from A? Your walking speed is always .

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  is uniformly chosen from interval [, 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  test cases. Each case begins with two integers n and D, where n ( <= n <= ) is the number of rivers between A and B, D ( <= D <= ) is the distance from A to B. Each of the following n lines describes a river with  integers: p, L and v ( <= p < D,  < L <= D,  <= v <= ). 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=, which should not be processed.
 
Output
For each test case, print the case number and the expected time, rounded to  digits after the decimal point.

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

 
Sample Output
Case : 1.000
Case : 1.000
 
 
 
 
Source
 
题目大意:A、B两点之间距离为D,并且在A、B之间有n条河,每条河上有一条自动船。船的宽度为L,把船看成一个点时,则它在第0时刻的位置是任意的,并且向两岸划动的可能性也是相同的。已知步行的速度为1,船的速度为v,每条河与A点的距离为P,求A到B花费的时间是多少。
 
分析:由题意不难得出,船在0时刻在河上的位置满足均匀分布,那么由均匀分布我们可知它的数学期望E = L/2。船向左岸划的概率等于向右岸划的概率为1/2,因为人只有通过船到左岸上船,再向右岸划动,才能过河。所以当船向左岸划的时候,那它到达左岸的期望时间T1 = L/2 * 1/2 / v;当船向右岸划,那它到达的左岸的期望时间T2 = (L/2 + L) * 1 / 2 / v;最后再从左岸到右岸的时间为T3 = L / v;所以过河的总期望时间为T = T1 + T2 + T3 = 2L / v;
 #include<stdio.h>
int main()
{
int n, i, cas = , d, p, l, v;
while(~scanf("%d%d",&n,&d), n+d)
{
double ans = d*1.0;
for(i = ; i < n; i++)
{
scanf("%d%d%d",&p, &l, &v);
ans -= l; //减去不过这条河时所用的时间
ans += 2.0*l / v; //加上过河时间
}
printf("Case %d: %.3lf\n\n",++cas, ans);
}
return ;
}

hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)的更多相关文章

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

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

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

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

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

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

  4. poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)

    Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...

  5. HDU 5858 Hard problem (数学推导)

    Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...

  6. UVA.12230.Crossing Rivers(期望)

    题目链接 /* 到达一条河时,船在河中的位置是随机的,所以船到达岸边需要的时间在 0~2l/v 均匀分布,所以船到岸的期望为 (0+2l/v)/2 过河需要 l/v 的时间,所以过一条河总的期望为 ( ...

  7. hdu 5584 LCM Walk(数学推导公式,规律)

    Problem Description A frog has just learned some number theory, and can't wait to show his ability t ...

  8. hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题

    题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...

  9. HDU 4772 Zhuge Liang's Password (2013杭州1003题,水题)

    Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

随机推荐

  1. struts的ognl.NoConversionPossible错误

    JSP页面便利集合的时候,代码如下 <s:iterator value="storageList" id="stList" status="st ...

  2. poj 2441 Arrange the Bulls(状态压缩dp)

    Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...

  3. jquery Tabs选项卡切换

    效果: HTML部分: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  4. [Regular Expressions] Find Repeated Patterns

    Regular Expression Quantifiers allow us to identify a repeating sequence of characters of minimum an ...

  5. 使用Win32::OLE操作Excel——Excel对象模型

    像VBA操作Excel一样,Win32::OLE模块也是通过对象操作来控制Excel. 如果想自动化操作和控制Excel应用程序,则必须要与Excel对象模型所提供的对象进行交互.理解和熟悉Excel ...

  6. python进阶之路之文件处理

    Python之文件处理 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !imp ...

  7. C#中唯一标识符GUID的一些知识点

    概念 GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier) . GUID是一个通过特定算 ...

  8. Windows命令行(DOS命令)教程-4(转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_3.html

    2. md md是英文make directory(创建目录)的缩写 [功能] 创建一个子目录 [格式] md [C:]path [举例] 用md 建立一个叫做purple的目录 3. cd cd是英 ...

  9. Oracle 批量操作

    背景: 前两天由于工作需要做个业务单据接口(支持批量处理),一般有接口发布为批量,但访问数据库时还是一张张单据处理,本次访问数据库也是批量操作.   内容: 研究发现Oracle批量操作有两种:1)B ...

  10. 吸血鬼数字算法参考 -- javascript版本

    // 吸血鬼数字 java编程思想 第四章 75页 练习10 for (var i = 10; i <= 99; i++) { for (var j = i + 1; j < 99; j+ ...