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

题意:有个人每天要去公司上班,每次会经过N条河,家和公司的距离为D,默认在陆地的速度为1,给出N条河的信息,包括起始坐标p,宽度L,以及船的速度。船会往返在河的两岸,人到达河岸是,船的位置是随机的(包括方向)。问说人达到公司所需要的期望时间。

题解:由于有方向我们单纯算过河时间的话,最快的是l/v,最慢的可能是3l/v,期间的时间是线性的,所以期望就是4l/2v=2l/v,加上陆地的单位时间就可以了

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll;
const int N=+;
int main() {
int cas = , n;
double d, p, l, v;
while(~scanf("%d%lf",&n,&d)) {
if(n == && d == ) break;
for(int i = ;i < n; i++) {
scanf("%lf%lf%lf",&p,&l,&v);
d = d - l + l * / v;
}
printf("Case %d: %.3f\n\n", cas++, d);
}
return ;
}

代码

UVA - 12230 Crossing Rivers 概率期望的更多相关文章

  1. UVA 12230 - Crossing Rivers(概率)

    UVA 12230 - Crossing Rivers 题目链接 题意:给定几条河,每条河上有来回开的船,某一天出门,船位置随机,如今要求从A到B,所须要的期望时间 思路:每条河的期望,最坏就是船刚开 ...

  2. UVA - 12230 Crossing Rivers (期望)

    Description You live in a village but work in another village. You decided to follow the straight pa ...

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

    你住在村庄A,每天需要过很多条河到另一个村庄B上班,B在A的右边,所有的河都在A,B之间,幸运的是每条船上都有自由移动的自动船, 因此只要到达河左岸然后等船过来,在右岸下船,上船之后船的速度不变.现在 ...

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

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

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

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

  6. UVA - 12230 Crossing Rivers(过河)(期望)

    题意:从A到B需要经过n条河,已知AB间距离D和每条河的长度L以及在该条河上的船速v,求A到B平均情况下需多长时间.陆地行走速度为1,船的位置和朝向均匀随机. 分析: 1.过一条河,最短时间L/v(无 ...

  7. UVA 12230 Crossing Rivers

    嘟嘟嘟 虽然分类是期望dp,不过好像是最水的 因为在陆地上的时间和概率是固定的,所以只用考虑过河的期望时间. 对于一条河p, l, v,p好像没什么用……不管了,首先期望时间我觉得可以这么算:期望时间 ...

  8. HDU3232 Crossing Rivers 数学期望问题

    Crossing Rivers                                                                                     ...

  9. hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)

    Problem Description   You live in a village but work in another village. You decided to follow the s ...

随机推荐

  1. react拼接class&将JS标签转换为HTML

    1.在JS中混杂字符和HTML标签,识别方法: const menuList = ['门店', '星享俱乐部', '菜单', '<hr></hr>', '星巴克移动应用', ' ...

  2. vs添加浏览器

    点击桌面谷歌图标,查看属性,赋值全部地址 在vs中,直接添加,把地址复制进去就ok了

  3. (转) RabbitMQ学习之发布/订阅(java)

    http://blog.csdn.net/zhu_tianwei/article/details/40887733 参考:http://blog.csdn.NET/lmj623565791/artic ...

  4. Vue2:实例生命周期、js生命周期

    1.vue2生命周期 每个 Vue 实例在被创建之前都要经过一系列的初始化过程.例如,实例需要配置数据观测(data observer).编译模版.挂载实例到 DOM ,然后在数据变化时更新 DOM ...

  5. jQuery 父级,祖先,兄弟,等选择性操作

    jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(&q ...

  6. Day 13迭代器生成器

    迭代器 1.迭代器就是迭代的工具,迭代也可以说成是重复,并且每一次重复都是基于上一次的结果而来的,在python中一切皆对象. 2.可迭代对象:只要拥有__iter__方法的对象都是可迭代对象. 3. ...

  7. Python爬虫2------爬虫屏蔽手段之代理服务器实战

      1.代理服务器: 一个处于客户端与互联网中间的服务器,如果使用代理服务器,当我们浏览信息的时候,先向代理服务器发出请求,然后由代理服务器向互联网获取信息,再返回给我们. 2.代码: import ...

  8. SQL 到 NOSQL 的思维转变

    转自:http://blogread.cn/it/article/3130?f=wb SQL 到 NOSQL 的思维转变 NOSQL系统一般都会宣传一个特性,那就是性能好,然后为什么呢?关系型数据库发 ...

  9. XSS Chanllenges 6-10

    Stage #6 测试代码</xss> 存在过滤,并且也没有其他输入点,尝试构建" onmousemove="alert(document.domain),并查看源代码 ...

  10. 30 包含min函数的栈(举例让抽象问题具体化)

    题目描述: 定义栈的数据结构(push/pop),请在该类型中实现一个能够得到栈中所含最小元素的min函数(三者的时间复杂度都应为O(1)). 测试用例: 1)新压入栈的数字比之前的最小值大/小 2) ...