码迷,mamicode.com
首页 > 其他好文 > 详细

『UVA 12230』Crossing Rivers (简单期望)

时间:2018-09-06 02:47:09      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:int   href   ike   ever   一点   question   not   algorithm   math   

题目链接戳这里

题目描述

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.


中文翻译

现在从A到B的长度为\(D\),并且A到B之间有\(n\)条河,每条河的长度为\(L_i\),每条河上又一条船以\(V_i\)来回运行,在0时刻人出发,并且每艘船在0时刻会随机出现在河上的一个位置,方向随机。人在陆地上行走的速度恒为\(1\),求从A到达B的时间的期望值。



解题思路

乍一看没啥思路,像一道概率\(dp\),其实仔细想想,这是一道假题。

首先,渡每条河的时间期望都是独立的,互不影响,这是最假的一点。其次,我们发现度过一条河的最快时间是\(\frac{L_i}{V_i}\),最慢时间是\(\frac{3*L_i}{V_i}\),我们发现,在\([\frac{L_i}{V_i},\frac{3*L_i}{V_i}]\)之间,每个值取到的概率是相同的,那平均下来就是\(\frac{2*L_i}{V_i}\),然后就完了qwq



代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    int n,d,cas=0;
    while(~scanf("%d%d",&n,&d)){
        if(n==0&&d==0)return 0;
        double ans=0;
        cas++;
        for(register int i=1,p,l,v;i<=n;i++){
            scanf("%d%d%d",&p,&l,&v);
            d-=l;
            ans+=l*2.0/v;
        }
        ans+=d;
        printf("Case %d: %.3lf\n\n",cas,ans);
    }
}

『UVA 12230』Crossing Rivers (简单期望)

标签:int   href   ike   ever   一点   question   not   algorithm   math   

原文地址:https://www.cnblogs.com/Fang-Hao/p/9595554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!