UVa12230 - Crossing Rivers

题意

A到B之间需要过N条河,AB间的总长度为D,每条河的左端与A的距离为P,河的长度为L,每条河上都有一艘船,船的速度为V,船所在位置随机,且开的方向随机,问过河时间的期望。

思路

过每条河的时间为L/V到3L/V的均匀分布,所以过每条河的期望时间为(L/V+3L/V)/2,再加上在岸上走的时间,即为总时间。

总结

期望的计算。期望属于弱项,要多加练习,题目并不难,就是不是太理解。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 int kase = 0, n;
 7 int main()
 8 {
 9     //freopen("in.txt","r",stdin);
10     double d, p, l, v;
11     while(scanf("%d %lf", &n, &d) && (n || d)){
12         double ans = 0,tmp = 0.0;
13         for(int i = 0; i < n; i++){
14             scanf("%lf %lf %lf", &p, &l, &v);
15             tmp += l*1.0;
16             ans += 2.0*l/v;
17         }
18         printf("Case %d: %.3lf\n\n",++kase, ans+d-tmp);
19     }
20     return 0;
21 }

 

转载于:https://www.cnblogs.com/kikii233/p/5972502.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值