HDU 3232 Crossing Rivers

来源:互联网 发布:抗衰老精华 知乎 编辑:程序博客网 时间:2024/06/05 22:09

Crossing Rivers

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1040 Accepted Submission(s): 535

Problem 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 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.

Input

There will be at most 10 test cases. Each case begins with two integers n and D, where n (0 <= n <= 10) is the number of rivers between A and B, D (1 <= D <= 1000) is the distance from A to B. Each of the following n lines describes a river with 3 integers: p, L and v (0 <= p < D, 0 < L <= D, 1 <= v <= 100). p is the distance from A to the left bank of this river, L is the length of this river, v is the speed of the boat on this river. It is guaranteed that rivers lie between A and B, and they don’t overlap. The last test case is followed by n=D=0, which should not be processed.

Output

For each test case, print the case number and the expected time, rounded to 3 digits after the decimal point.

Print a blank line after the output of each test case.

Sample Input

1 1
0 1 2
0 1
0 0

Sample Output

Case 1: 1.000

Case 2: 1.000

A B 两个点间有n条河,河长、船速已知,求时间期望

我们单纯算过河时间的话,最快的是L/v,最慢的是3L/v,时间是满足线性变化规律,所以期望就是4L/2v=2L/v
(线性规划,三角形面积)

AC

#include <cstdio>#include <cstdlib>int main(){    int n,d;    int cnt=0;    while(scanf("%d%d",&n,&d))    {        if(n==0&&d==0)            break;        double time=0.0;        if(n!=0)        {            for(int i=0; i<n; i++)            {                int p,L,v;                scanf("%d%d%d",&p,&L,&v);                time+=(2.0*L)/v;                d-=L;            }        }        cnt++;        printf("Case %d: ",cnt);        printf("%.3f\n\n",time+d);    }    return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 散热硅胶干了怎么办 电脑打不开pdf文件怎么办 文件变成快捷方式打不开怎么办 ai文件打不开了怎么办 电脑下载了病毒软件怎么办 打嗝停不下来怎么办 咳嗽停不下来怎么办 电动机停不下来怎么办 电脑所有程序都打不开怎么办 机顶盒画面卡顿怎么办 电脑画面卡顿怎么办 鞋舌头跑偏怎么办 球球大作战老卡怎么办 孩子被打却不敢还手怎么办? 自卫砍伤了人怎么办 系统还原节点黑屏了怎么办 我惹事了要被打怎么办 诛仙宠物太多怎么办 笔记本玩lolfps低怎么办 lol延迟有42怎么办 软件安装后黑屏怎么办 汽车脚垫翘边怎么办 晴季寿司会员怎么办 理财产品跑路了怎么办 宝宝足跟血异常怎么办 孩子足跟血异常怎么办 打印机显示用户干预怎么办 打印机脱机状态怎么办win10 电脑打印机显示脱机怎么办 佳能打印机显示脱机怎么办 汽车说明书丢了怎么办 oppo手机刷机后内存不足怎么办 电脑运行太慢怎么办 台式电脑卡慢怎么办 touch炫舞不记得区怎么办 产能过剩是带怎么办 裸辞找不到工作怎么办 30岁找不到工作怎么办 20岁找不到工作怎么办 年轻人一直找不到工作怎么办 经济不好的时候怎么办