HDU3232 Crossing rivers

思路:这题关键一点就是根据题目的描述和测试数据得到启发,船都是

   从对岸划过来的。心中有具体场景,就可以很简单了。

 1 #include<cstdio>
 2 int main()
 3 {
 4     double d, p, l, v, sum, flag = 0;
 5     int n, kase = 1;
 6     while(~scanf("%d %lf", &n, &d))
 7     {
 8         if(n == 0 && d == 0) break; //跳出
 9         sum = 0;
10         while(n--)
11         {
12             scanf("%lf %lf %lf", &p, &l, &v);
13             sum += 2*l/v; //船从对岸过来,再过河,在水上共花费的时间
14             d -= l; //剩余的就是陆地上的长度。
15         }
16         if(n == 0)
17         {
18             printf("Case %d: ", kase ++); //n为0时则直接输出d
19             printf("%.3lf\n", d);
20             continue;
21         }
22         sum += d;   //直接加上陆地上的长度,就是总时间
23         //if(flag ++) printf("\n"); //刚开始用的是这步,结果PE了一发。
24         printf("Case %d: ", kase ++);
25         printf("%.3lf\n\n", sum); //注意输出格式
26     }
27     return 0;
28 }

时间: 2024-10-15 14:55:21

HDU3232 Crossing rivers的相关文章

HDU3232 Crossing Rivers 数学期望问题

Crossing Rivers                                                                                      Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description You live in a village but work in another vil

UVA 12230 - Crossing Rivers(概率)

UVA 12230 - Crossing Rivers 题目链接 题意:给定几条河,每条河上有来回开的船,某一天出门,船位置随机,现在要求从A到B,所需要的期望时间 思路:每条河的期望,最坏就是船刚开走3L/V,最好就是直接上船L/V,期望为4L/V/2 = 2L/V,然后在算上陆地上的时间,就是答案 代码: #include <stdio.h> #include <string.h> int n; double d, p, l, v; int main() { int cas =

HDOJ 3232 Crossing Rivers 简单概率

简单期望: 船到岸边时间的期望是 L/v 再过河的时间是L/v 所以过每条河的时间期望是2*L/v Crossing Rivers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 699    Accepted Submission(s): 361 Problem Description You live in a village bu

uva 12230 - Crossing Rivers(求数学期望)

利用了数学期望的线性性质:有线个随机变量之和的数学期望的关于每个随机变量的期望之和: 由于过每条河的时间为L / V和3L / V的均匀分布,因此期望过河时间为2L / V. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n;double d; int main() { int kase=0; while(scanf("%d%lf",&a

UVA - 12230 Crossing Rivers (期望)

Description 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

UVA - 12230 Crossing Rivers 概率期望

You live in a village but work in another village. You decided to follow the straight path between yourhouse (A) and the working place (B), but there are several rivers you need to cross. Assume B is tothe right of A, and all the rivers lie between t

『UVA 12230』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 river

Crossing Rivers UVA - 12230

题意:你住在村庄A,每天需要过很多条河到村庄B去,B在A的右边,所有的河都在中间.幸运的是,每条河上都有匀速移动的自动船,因此每当 到达一条河的左岸时只需等船过来,载着你过河,然后在右岸下船.问:从A到B,平均情况下需要多长时间?假设在出门时所有船的位置都是随 机均匀分布的.如果位置不是在河的端点,则朝向也是随机的.在陆地上行走的速度时1. 题解:用数学期望的线性.过每条河的时间为 l/v 到 3l/v 的均匀分布,因此每条河期望过河时间 2l/v . ---------------------

UVa12230 - Crossing Rivers (数学期望)

题意:给你A和B的距离,以及途中n条河的信息,问你从A到B的期望 思路:我们单纯算过河时间的话,最快的是l/v,最慢的可能是3l/v,期间的时间是线性的,所以期望就是4l/2v=2l/v #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> int main() { int n; double p,l,v,d; int cas=1; while(scanf(&quo