HDU3232 Crossing Rivers 数学期望问题
Crossing Rivers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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 chosenfrom interval [0, L], and the boat is equally like to be moving left
or right, if it’s not precisely at the river bank.
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.
Print a blank line after the output of each test case.
0 1 2
0 1
0 0
Case 2: 1.000
= 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 ;
}
HDU3232 Crossing Rivers 数学期望问题的更多相关文章
- Uva - 12230 Crossing Rivers (数学期望)
你住在村庄A,每天需要过很多条河到另一个村庄B上班,B在A的右边,所有的河都在A,B之间,幸运的是每条船上都有自由移动的自动船, 因此只要到达河左岸然后等船过来,在右岸下船,上船之后船的速度不变.现在 ...
- UVA12230 Crossing Rivers (数学期望)
题目链接 题意翻译 一个人每天需要从家去往公司,然后家与公司的道路是条直线,长度为 \(D\). 同时路上有 \(N\) 条河,给出起点和宽度\(W_i\) , 过河需要乘坐速度为\(V_i\) 的渡 ...
- hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)
Problem Description You live in a village but work in another village. You decided to follow the s ...
- UVA - 12230 Crossing Rivers (期望)
Description You live in a village but work in another village. You decided to follow the straight pa ...
- Uva12230Crossing Rivers (数学期望)
问题: You live in a village but work in another village. You decided to follow the straight path betwe ...
- UVA - 12230 Crossing Rivers 概率期望
You live in a village but work in another village. You decided to follow the straight path between y ...
- HDU3232 Crossing rivers
思路:这题关键一点就是根据题目的描述和测试数据得到启发,船都是 从对岸划过来的.心中有具体场景,就可以很简单了. #include<cstdio> int main() { ; ; whi ...
- 【整理】简单的数学期望和概率DP
数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么 ...
- UVa 12230 && HDU 3232 Crossing Rivers (数学期望水题)
题意:你要从A到B去上班,然而这中间有n条河,距离为d.给定这n条河离A的距离p,长度L,和船的移动速度v,求从A到B的时间的数学期望. 并且假设出门前每条船的位置是随机的,如果不是在端点,方向也是不 ...
随机推荐
- IOS 图形上下文栈
- (void)drawRect:(CGRect)rect { // 获取上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); // 保存一份最纯 ...
- Aizu 0525 Osenbei(状压+贪心)
题意:翻煎饼,只能横着翻或者竖着翻.问最多有多少朝上? 行只有10,所以枚举一下2^10的状态,每列取0或1中最大的一个. 在枚举外面把饼翻好,枚举里面指针指一下就好.(位运算或bitset乱搞 #i ...
- 使用VSCode搭建TypeScript开发环境 (重点)
下载TypeScript 在CMD(Windows系统)或者终端(macOS系统)中输入一下命令: npm install -g typescript 下载VSCode VSCode是我使用过最棒的编 ...
- 说说qwerty、dvorak、colemak三种键盘布局
[qwerty布局] qwerty布局大家应该都很熟悉了,全世界最普及的键盘布局. 截止到去年接触并使用dvorak布局之前,我使用了十几年qwerty布局,在http://speedtest.10f ...
- js处理的8种跨域方法
这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协议.域名.端口有任何一个不同,都被 ...
- jfinal excel表导出
在自己的WEB项目中要用到导出Excel,所以结合网络上的资源写了一个自己的export 工具类. 说明: JFinal 环境 WEB项目 JAVA后台生成非JS插件 好了,直接撸代码 1.设置文件保 ...
- gulp的常用插件
gulp和webpack的差别:https://www.cnblogs.com/lovesong/p/6413546.html var gulp = require('gulp'); var del ...
- 洛谷P1164小A点菜
这也是一道01背包的题 用的方法比较的巧妙.这个动态规划相当于反过来做的,自己理解就知道了.代码很短 #include<bits/stdc++.h> using namespace std ...
- 自动化运维工具——ansible安装入门(一)
一.简介 现如今有很多运维自动化的工具,如:Ansible.Puppet.saltStack.Fabric.chef.Cfengine 1. Ansible介绍 Ansible 是由 Cobbler与 ...
- Git 内部原理之 Git 对象哈希
在上一篇文章中,将了数据对象.树对象和提交对象三种Git对象,每种对象会计算出一个hash值.那么,Git是如何计算出Git对象的hash值?本文的内容就是来解答这个问题. Git对象的hash方法 ...