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(0n10)
is the number of rivers between A and B, D(1D1000)
is the distance from A to B. Each of the following n lines describes a river with 3 integers:
p, L and
v (0p <
D, 0 < LD,
1v100).
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
题意:给你A和B的距离。以及途中n条河的信息。问你从A到B的期望
思路:我们单纯算过河时间的话,最快的是l/v,最慢的可能是3l/v,期间的时间是线性的,所以期望就是4l/2v=2l/v
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std; int n;
double p, l, v, d; int main() {
int cas = 1;
while (scanf("%d%lf", &n, &d) != EOF && n+d) {
while (n--) {
scanf("%lf%lf%lf", &p, &l, &v);
d = d - l + l * 2 / v;
}
printf("Case %d: %.3lf\n\n", cas++, d);
}
return 0;
}

UVA - 12230 Crossing Rivers (期望)的更多相关文章

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

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

  2. UVA 12230 - Crossing Rivers(概率)

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

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

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

  4. UVA - 12230 Crossing Rivers 概率期望

    You live in a village but work in another village. You decided to follow the straight path between y ...

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

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

  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. Crossing Rivers UVA - 12230 概率与期望

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

  9. 紫书 例题 10-16 UVa 12230(数学期望)

    感觉数学期望的和化学里面求元素的相对原子质量的算法是一样的 就是同位素的含量乘上质量然后求和得出 这道题因为等待时机是0到2*l/v均匀分配的,所以平均时间就是l/v 再加上过河的l/v, 最后加上步 ...

随机推荐

  1. Ubuntu14.04 64bit安装Android-Studio

    用PPA安装Android-Studio炒鸡简单,墙内亲测可用,就是速度慢了点.(睡觉时开着电脑装-) 安装Android-Studio 打开Terminal,执行: sudo add-apt-rep ...

  2. Android-设置PullToRefresh下拉刷新样式

    以下是开源控件PullToRefresh的自定义样式属性: <?xml version="1.0" encoding="utf-8"?> <r ...

  3. jquery submit()不能提交表单的解决方法

    <form id="form" method="get"> <input type="text" name="q ...

  4. cocos2dx 字体

    有些时候需要在界面上显示些文字,自然涉及到字体的问题 显示文字使用CCLabelTTF即可,创建方法是 CCLabelTTF(const char* text, const char* font, i ...

  5. HDU 5758 Explorer Bo(树形DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5758 [题目大意] 给出一棵树,每条路长度为1,允许从一个节点传送到任意一个节点,现在要求在传送次 ...

  6. AspectJ给类的属性打桩,进行替换。

    这个东西必须写个博客记一下了,一方面是防止以后忘记,一方面也反思一下自己的固执. 在我们的代码中,通常会有一些配置文件的路径写死在代码里面.比如 public class ConfigPath { p ...

  7. Java内存模型-jsr133规范介绍

    原文地址:http://www.cnblogs.com/aigongsi/archive/2012/04/26/2470296.html; 近期在看<深入理解Java虚拟机:JVM高级特性与最佳 ...

  8. 汉诺塔 python版

    汉诺塔问题:如果将n个盘子(由小到大)从a通过b,搬到c,搬运过程中不能出现小盘子在大盘子下面的情况. 思路分析:假设前要移动第100个盘子,分两步走,移动第99个:再移动第100个:而要移动第99个 ...

  9. 笔记-Nodejs中的核心API之Events

    最近正在学习Node,在图书馆借了基本关于Node的书,同时在网上查阅资料,颇有收获,但是整体感觉对Node的理解还是停留在一个很模棱两可的状态.比如Node中的模块,平时练习就接触到那么几个,其他的 ...

  10. ASP.NET之电子商务系统开发-3(订单)

    一.前言 继上次的购物车,这是第三篇.记录一下订单功能.这功能做的时候,走过弯路,很是烧脑,因为思路没理顺,数据库设计的也不怎么好,做到一半才发现有问题,接着把数据库重新设计好,理清思路后,终于完成了 ...