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条 ...
随机推荐
- windows10更换mysql8.0.17
下载windows版本mysql 解压后创建my.ini文件初始化mysql和data文件夹用来存数据 my.ini内容 [mysqld] # 设置3306端口 port=3306 # 设置mysql ...
- spingboot中使用scheduled设置定时任务注意事项
在spring开发过程中经常会遇到需要定时执行的任务,如定时生成报表,定时推送消息等任务. springboot 提供了简单的 @Scheduled 表达式来配置定时任务.该方式默认是单线程的,任务在 ...
- python-python基础2
本章内容: 1.列表.元组 2.字典 3.集合 4.文件操作 5.字符编码与转码 一.列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 names= ...
- ubuntu安装discourse论坛----结合在apache服务上建立虚拟主机
指导操作:https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md 一.先安装 Docker / Git: wg ...
- PostgreSQL数据库-抽奖sql
select * from users order by random();--会进行随机排序,每次运行都会返回不同的结果 select * from users order by random() ...
- Codeforces 591 B:Rebranding
B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 实验吧——Recursive
环境:win10,kali虚拟机 工具:ida 虚拟机打开看看,发现是ELF文件,运行一下,额没有什么发现. Ida打开看看,发现是在文件内部运行python解释器,百度搜索了一个基本上可以找到Py_ ...
- HIWORD HIBYTE
#include "pch.h" #include <iostream> #include<Windows.h> int main() { ; WORD i ...
- Redis原理详解
Redis原理详解 数据类型 Redis最为常用的数据类型主要有以下五种: String Hash List Set Sorted set 在具体描述这几种数据类型之前,我们先通过一张图了解下Redi ...
- R 读取回归模型的信息
参考博客: http://blog.sina.com.cn/s/blog_8f5b2a2e0101fmiq.html https://blog.csdn.net/huangyouyu523/artic ...