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. 基于Verilog语言的可维护性设计技术

    [注]本文内容主体部分直接翻译参考文献[1]较多内容,因此本文不用于任何商业目的,也不会发表在任何学术刊物上,仅供实验室内部交流和IC设计爱好者交流之用. “曲意而使人喜,不若直节而使人忌:无善而致人 ...

  2. WebServic调用天气预报服务

    在项目开发中,我们除了发布WebService提供客户调用外,也经常需要调用一些客户或者第三方的WebService服务,这里就通过一个Demo来演示调用一个第三方的天气预报服务. 1.天气预报服务接 ...

  3. Python demo working

    一.游戏1.2.3 print("-------------- Guess Number Game---------------------") num=input("G ...

  4. 记一次 CORS 跨域请求出现 OPTIONS 请求的问题及解决方法

    今天前后端在联调接口的时候,发生了跨域请求资源获取不到的问题. 首先说明下跨域问题的由来.引自HTTP 访问控制 的一段话: 当 Web 资源请求由其它域名或端口提供的资源时,会发起跨域 HTTP 请 ...

  5. 如何获取repeater某行第一列的值

    <div> <asp:Repeater ID="Repeater1" runat="server" DataMember="Defa ...

  6. Android开发系列(十六):【Android小游戏成语连连看】第二篇

    写的晚了,在分工个Z市高中的一个成绩查询的系统,原系统居然是用VB写的,我不得不佩服原本写系统的那位哥们真能耐得住. 明天搭建下SVN就等着先发project款然后開始项目了.想想有工资进账,心里也为 ...

  7. 针对CDP协议攻击分析及安全防护

    针对CDP协议攻击分析及安全防护 熟悉Cisco的朋友都知道CDP协议是思科公司独特的发现协议,在思科公司出产的所有路由器和交换机里面都能运行此协议,一台运行C D P的路由器或交换机能够得知与它直接 ...

  8. ES6--基础语法(一)

    一.支持环境:node.js完全支持,标准浏览器完全支持.二.测试环境: chrome下需要在script标签的最先开始的地方需要添加"use strict". firefox下需 ...

  9. 程序中为什么会使用while(0)

    https://blog.csdn.net/u012062760/article/details/46446207 关于while(0)实际上是用来宏定义的,这样的宏定义可以避免调用的时候出错. 如下 ...

  10. Activemq去除认证

    0.背景介绍 由于项目安全性的约束,不能在配置文件中暴露一些密码信息.   默认情况下,ActiveMQ在进行接发消息的时候会用户认证.通过ActiveMQ-client初始化ActiveMQConn ...