UVA - 12230 Crossing Rivers(过河)(期望)
题意:从A到B需要经过n条河,已知AB间距离D和每条河的长度L以及在该条河上的船速v,求A到B平均情况下需多长时间。陆地行走速度为1,船的位置和朝向均匀随机。
分析:
1、过一条河,最短时间L/v(无需等船),最长时间3L/v(要坐船时,船正好驶离自己所在的河岸),所以平均时间为2L/v。
2、再算出陆地行走距离,D-sum[L],求出陆地行走时间。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b) {
if(fabs(a - b) < eps) return 0;
return a < b ? -1 : 1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
int n, D;
int kase = 0;
while(scanf("%d%d", &n, &D) == 2){
if(!n && !D) return 0;
int sum = 0;
double ans = 0;
for(int i = 0; i < n; ++i){
int p, L, v;
scanf("%d%d%d", &p, &L, &v);
sum += L;
ans += double(2 * L) / v;
}
ans += D - sum;
printf("Case %d: %.3lf\n\n", ++kase, ans);
}
return 0;
}
UVA - 12230 Crossing Rivers(过河)(期望)的更多相关文章
- UVA - 12230 Crossing Rivers (期望)
Description You live in a village but work in another village. You decided to follow the straight pa ...
- UVA - 12230 Crossing Rivers 概率期望
You live in a village but work in another village. You decided to follow the straight path between y ...
- Uva - 12230 Crossing Rivers (数学期望)
你住在村庄A,每天需要过很多条河到另一个村庄B上班,B在A的右边,所有的河都在A,B之间,幸运的是每条船上都有自由移动的自动船, 因此只要到达河左岸然后等船过来,在右岸下船,上船之后船的速度不变.现在 ...
- UVA 12230 - Crossing Rivers(概率)
UVA 12230 - Crossing Rivers 题目链接 题意:给定几条河,每条河上有来回开的船,某一天出门,船位置随机,如今要求从A到B,所须要的期望时间 思路:每条河的期望,最坏就是船刚开 ...
- UVa 12230 - Crossing Rivers(数学期望)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA.12230.Crossing Rivers(期望)
题目链接 /* 到达一条河时,船在河中的位置是随机的,所以船到达岸边需要的时间在 0~2l/v 均匀分布,所以船到岸的期望为 (0+2l/v)/2 过河需要 l/v 的时间,所以过一条河总的期望为 ( ...
- UVA 12230 Crossing Rivers
嘟嘟嘟 虽然分类是期望dp,不过好像是最水的 因为在陆地上的时间和概率是固定的,所以只用考虑过河的期望时间. 对于一条河p, l, v,p好像没什么用……不管了,首先期望时间我觉得可以这么算:期望时间 ...
- HDU3232 Crossing Rivers 数学期望问题
Crossing Rivers ...
- hdu 3232 Crossing Rivers 过河(数学期望)
题意:你在点A,目的地是点B,A和B的距离为D.中间隔了好多条河(所有河不会重叠),每条河有3个参数(P,L,V),其中P表示距离A点的长度,L表示河的长度,V表示河里的船的速度.假设每条河中仅有1条 ...
随机推荐
- ch8 高度相等的列--CSS方法
如下图所示效果,可以使用表格实现,本文采用在CSS中实现. 标记如下: <div class="wrapper"> <div class="box&qu ...
- Lesson 47 The great escape
What is one of the features of modern camping where nationality is concerned? Economy is one powerfu ...
- CSS-lineheight
.test div{width:300px;margin:15px 0;border:1px solid #000;}.test p{margin:0;font-size:30px;}.fixed d ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:为图片添加圆角 (IE8 不支持)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- greenplum 存储过程 变量类型
参考: https://www.cnblogs.com/kungfupanda/p/4478917.html
- POJ1471 Tree/洛谷P4178 Tree
Tree P4178 Tree 点分治板子. 点分治就是直接找树的重心进行暴力计算,每次树的深度不会超过子树深度的\(\frac{1}{2}\),计算完就消除影响,找下一个重心. 所以伪代码: voi ...
- R 误差自相关与DW检验
R语言进行DW检验: library(lmtest) dw = dwtest(fm1) > dw Durbin-Watson test data: fm1 DW = 2.4994, p-valu ...
- log4j配置文件——hibernate
log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j ...
- git克隆项目后的操作
使用https路径clone代码后,如果直接提交,会出现两个问题: 1. 提交的用户是操作系统登陆用户: 2. 需要重复输入用户名和密码: 一 设置用户名和邮箱 git config user.nam ...
- LCD驱动详解
参考文档:<液晶屏.pdf><S3C2440用户手册><JZ2440-V3原理图> frame buffer: 显存,用于存放LCD显示数据:frame buf ...