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. 5. webservice通信调用天气预报接口实例

    转自:https://blog.csdn.net/xiejuan6105/article/details/78452605 一:环境搭建 1:新建一个java project工程weatherInf ...

  2. shrio 加密/编码

    在涉及到密码存储问题上,应该加密/生成密码摘要存储,而不是存储明文密码.比如之前的600w csdn账号泄露对用户可能造成很大损失,因此应加密/生成不可逆的摘要方式存储. 5.1 编码/解码 Shir ...

  3. 洛谷P4051 [JSOI2007]字符加密

    题目描述 喜欢钻研问题的JS 同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法:把需要加密的信息排成一圈,显然,它们有很多种不同的读法. 例如‘JSOI07’,可以读作 ...

  4. nodejs-website

    http://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs http://nodeapi.ucdok.com/ ...

  5. OpenCV中数据转换

    在OpenCV中Mat.CvMat和IplImage类型都可以代表和显示图像.IplImage由CvMat派生,而CvMat由CvArr派生即CvArr -> CvMat -> IplIm ...

  6. CentOS yum安装mcrypt详细图解教程

    CentOS yum安装mcrypt详细图解教程 在Linux的发行版CentOS 6.3 系统下,LAMP(Linux+Apache+Mysql+php)环境搭建好后发现PHPMyadmin提示 “ ...

  7. oracle查询字段大于指定长度的数据

    select * from MES_MACHINE_RECORD t where length(t.bar_code2)<10 ;

  8. Safe and efficient allocation of memory

    Aspects of the present invention are directed at centrally managing the allocation of memory to exec ...

  9. 洛谷 P3670 [USACO17OPEN]Bovine Genomics S奶牛基因组(银)

    P3670 [USACO17OPEN]Bovine Genomics S奶牛基因组(银) 题目描述 Farmer John owns NN cows with spots and NN cows wi ...

  10. Java 实现策略(Strategy)模式

    策略模式:行为型模式 将同一行为,不同的处理算法分别封装起来.让它们之间能够互相替换 1. 定义一个超类型接口,及 行为方法 2. 定义不同的实现类,实现该行为的 不同的算法 /** * 策略模式:针 ...