hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)
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 , what is the expected time to reach B from A? Your walking speed is always . 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 is uniformly chosen from interval [, L], and the boat is equally like to be moving left or right, if it’s not precisely at the river bank.
There will be at most test cases. Each case begins with two integers n and D, where n ( <= n <= ) is the number of rivers between A and B, D ( <= D <= ) is the distance from A to B. Each of the following n lines describes a river with integers: p, L and v ( <= p < D, < L <= D, <= v <= ). 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=, which should not be processed.
For each test case, print the case number and the expected time, rounded to digits after the decimal point. Print a blank line after the output of each test case.
Case : 1.000
Case : 1.000
#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 ;
}
hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)的更多相关文章
- UVa 12230 && HDU 3232 Crossing Rivers (数学期望水题)
题意:你要从A到B去上班,然而这中间有n条河,距离为d.给定这n条河离A的距离p,长度L,和船的移动速度v,求从A到B的时间的数学期望. 并且假设出门前每条船的位置是随机的,如果不是在端点,方向也是不 ...
- hdu 3232 Crossing Rivers 过河(数学期望)
题意:你在点A,目的地是点B,A和B的距离为D.中间隔了好多条河(所有河不会重叠),每条河有3个参数(P,L,V),其中P表示距离A点的长度,L表示河的长度,V表示河里的船的速度.假设每条河中仅有1条 ...
- UVa 12230 - Crossing Rivers(数学期望)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)
Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...
- HDU 5858 Hard problem (数学推导)
Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...
- UVA.12230.Crossing Rivers(期望)
题目链接 /* 到达一条河时,船在河中的位置是随机的,所以船到达岸边需要的时间在 0~2l/v 均匀分布,所以船到岸的期望为 (0+2l/v)/2 过河需要 l/v 的时间,所以过一条河总的期望为 ( ...
- hdu 5584 LCM Walk(数学推导公式,规律)
Problem Description A frog has just learned some number theory, and can't wait to show his ability t ...
- hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题
题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...
- HDU 4772 Zhuge Liang's Password (2013杭州1003题,水题)
Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
随机推荐
- hdu 5313 Bipartite Graph(dfs染色 或者 并查集)
Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...
- JavaScript学习总结(二)
JavaScript学习总结(二) ---- 对象 在JavaScript中,几乎用到的每个js都离不开它的对象.下面我们深入了解一下js对象. js中对象的分类跟之前我们学过的语言中函数的分类一样, ...
- Linux环境下Eclipse + Tomcat + MySQL 配置J2EE开发环境的方法
1. 版本号信息 (1)CentOS 6.4发行版64位,uname -a 显演示样例如以下: Linux localhost.localdomain 3.11.6 #1 SMP Sat Nov 2 ...
- LoadRunner监控windows资源报错Monitor name :Windows Resources. Cannot connect to machine
目标机:被监控的机器,windows server 2008 R2. 测试机:执行control的机器,windows7 操作:在测试机上执行Control,添加windows的监控 问题现象:Mon ...
- DEV SIT UAT
DEV环境:DEV顾名思义就是develop,即代码开发的环境.SIT环境:System Integration Test系统集成测试,开发人员自己测试流程是否走通.UAT环境:User Accept ...
- CSS基础知识之float
前段时间写过一篇CSS基础知识之position,当时对float的理解不太准确,被慕课网多名读者指出(原文已修正,如有误导实在抱歉).现对float进行更深入的学习,在此把学习心得分享给大家. 浮动 ...
- Javascript高级程序设计读书笔记(第三章)
第3章 基本概念 3.4 数据类型 5种简单数据类型:undefined.boolean.number.null.string. typeof操作符,能返回下列某个字符串:“undefined”.“b ...
- Java并发编程之ConcurrentHashMap
原文地址:http://www.iteye.com/topic/1103980 ConcurrentHashMap 是一个线程安全的Hash Table,它的主要功能是提供了一组和HashTable功 ...
- 4 常量类--Map常量
public static final HashMap<String, String> ETL_SOURCE_INPUTTYPE_MAP = new HashMap<String, ...
- Python学习笔记整理(四)Python中的字符串..
字符串是一个有序的字符集合,用于存储和表现基于文本的信息. 常见的字符串常量和表达式 T1=‘’ 空字符串 T2="diege's" 双引号 T3=""&quo ...