Problem Statement
Little Johnny woke up late. Now he only has timeLeft minutes to get to school.
Sadly, Johnny doesn't have a direct connection to school. He has to use three specific bus lines (one after another) to get there.
The buses in Johnny's town don't have a fixed schedule. Instead, each bus line is assigned some non-negative integer W. If you arrive at a bus stop of a bus line, you know that the time you will have to wait is a random variable drawn from the interval [0,W] with uniform probability. Note that from a passenger's point of view the number W corresponds to the maximum waiting time.
(You can imagine this in a real life setting as follows: If you stand on a bus stop of a line that has a positive W, precisely every W minutes a bus comes by, you just don't know the offset. If you stand on a bus stop of a line that has W=0, there is always a bus ready to take you.)
You are given two
Definition
- Class:
- ThreeBuses
- Method:
- getProbability
- Parameters:
- int[], int[], int
- Returns:
- double
- Method signature:
- double getProbability(int[] wait, int[] travel, int timeLeft)
- (be sure your method is public)
Notes
- Time is continuous, e.g., the bus can arrive 0.47 minutes after Johnny comes to a bus stop.
- Your return value must have an absolute or relative error less than 1e-9.
Constraints
- wait will contain exactly 3 elements.
- Each element of wait will be between 0 and 100,000, inclusive.
- travel will contain exactly 3 elements.
- Each element of travel will be between 1 and 100,000, inclusive.
- timeLeft will be between 1 and 600,000, inclusive.
Examples
{0, 0, 0}
{10, 15, 10}
47
Returns: 1.0
Johnny won't have to wait for the buses. He can be sure his trip will take exactly 35 minutes, and 35 is not more than 47.
{0, 0, 0}
{10, 15, 10}
35
Returns: 1.0
The same setting as before. With 35 minutes left, Johnny will arrive exactly on time.
{1, 100, 1}
{10, 10, 10}
52
Returns: 0.21
This time Johnny may get into trouble. It all depends on whether the second bus arrives soon enough. A rough estimate: if the second bus arrives in less then 20 minutes, Johnny will surely make it. Thus the exact probability is slightly over 20/100.
{100, 100, 70}
{1, 1, 1}
47
Returns: 0.020281904761904737
Johnny must be really lucky to make it.
{4,10,7}
{1,1,1}
1
Returns: 0.0
{4,10,7}
{1,1,1}
2
Returns: 0.0
{4,10,7}
{1,1,1}
3
Returns: 0.0
{4,10,7}
{1,1,1}
4
Returns: 5.952380952380952E-4
{4,10,7}
{1,1,1}
5
Returns: 0.004761904761904762
{4,10,7}
{1,1,1}
6
Returns: 0.016071428571428573
{4,10,7}
{1,1,1}
7
Returns: 0.03809523809523809
{4,10,7}
{1,1,1}
8
Returns: 0.07380952380952381
{4,10,7}
{1,1,1}
9
Returns: 0.12380952380952379
{4,10,7}
{1,1,1}
10
Returns: 0.1880952380952381
{4,10,7}
{1,1,1}
11
Returns: 0.2660714285714286
{4,10,7}
{1,1,1}
12
Returns: 0.3547619047619048
{4,10,7}
{1,1,1}
13
Returns: 0.45059523809523816
{4,10,7}
{1,1,1}
14
Returns: 0.549404761904762
{4,10,7}
{1,1,1}
15
Returns: 0.6452380952380954
{4,10,7}
{1,1,1}
16
Returns: 0.7339285714285715
{4,10,7}
{1,1,1}
17
Returns: 0.8119047619047619
{4,10,7}
{1,1,1}
18
Returns: 0.8761904761904763
{4,10,7}
{1,1,1}
19
Returns: 0.9261904761904761
{4,10,7}
{1,1,1}
20
Returns: 0.9619047619047618
{4,10,7}
{1,1,1}
21
Returns: 0.9839285714285712
{4,10,7}
{1,1,1}
22
Returns: 0.995238095238095
{4,10,7}
{1,1,1}
23
Returns: 0.9994047619047619
{4,10,7}
{1,1,1}
24
Returns: 1.0
{4,10,7}
{1,1,1}
25
Returns: 1.0
{97000,73000,84700}
{31200,72500,4700}
108400
Returns: 0.0
{97000,73000,84700}
{31200,72500,4700}
363100
Returns: 1.0
{97000,73000,84700}
{31200,72500,4700}
110000
Returns: 1.138231742537708E-6
{97000,73000,84700}
{31200,72500,4700}
108500
Returns: 2.7788860901800697E-10
{97000,73000,84700}
{31200,72500,4700}
363000
Returns: 0.9999999997221184
{97000,73000,84700}
{31200,72500,4700}
182000
Returns: 0.11079086486748652
{97000,73000,84700}
{31200,72500,4700}
194000
Returns: 0.17374176928710658
{97000,73000,84700}
{31200,72500,4700}
210000
Returns: 0.2835726246037114
{97000,73000,84700}
{31200,72500,4700}
240000
Returns: 0.5372445474231571
{97000,73000,84700}
{31200,72500,4700}
268000
Returns: 0.7643041560848166
{97000,73000,84700}
{31200,72500,4700}
278300
Returns: 0.8310000530201489
{97000,73000,84700}
{31200,72500,4700}
278400
Returns: 0.8315873286341242
{97000,73000,84700}
{31200,72500,4700}
278500
Returns: 0.8321733873738844
{97000,73000,84700}
{31200,72500,4700}
310000
Returns: 0.9583941587027168
{97000,73000,84700}
{31200,72500,4700}
108555
Returns: 1.0348224439069298E-9
{0,0,0}
{3,4,5}
11
Returns: 0.0
{1300,0,0}
{2,2,2}
576000
Returns: 1.0
{0,1470,0}
{20000,2,2}
47
Returns: 0.0
{0,0,1470}
{2,2,2}
47
Returns: 0.027891156462585033
{0,0,14700}
{20000,20000,20000}
74699
Returns: 0.9999319727891156
{1, 1, 1}
{1, 1, 1}
4
Returns: 0.16666666666666666
{2, 2, 2}
{1, 1, 1}
5
Returns: 0.16666666666666669
{4321,0,3173}
{1,1,1}
3
Returns: 0.0
{4321,0,3173}
{1,1,1}
7
Returns: 5.834929976828763E-7
{4321,0,3173}
{1,1,1}
2900
Returns: 0.306064286486893
{4321,0,3173}
{1,1,1}
3176
Returns: 0.3671603795417727
{4321,3173,0}
{1,1,1}
3420
Returns: 0.4236287896320296
{43210,31730,0}
{1,1,1}
43212
Returns: 0.6328164776672066
{43210,31730,0}
{1,1,1}
51500
Returns: 0.7995795462510464
{0,43210,31730}
{1,1,1}
74000
Returns: 0.9996757058970647
{100000,100000,100000}
{100000,100000,100000}
300000
Returns: 0.0
{89405,59302,77361}
{56684,87363,21865}
211599
Returns: 0.038750155606863484
{72753,34929,17514}
{89822,66339,37000}
278926
Returns: 0.8101835174696417
{61685,58761,90541}
{24176,76041,89533}
80845
Returns: 0.0
{46011,92612,31856}
{14687,73451,29343}
53508
Returns: 0.0
{20352,81660,95211}
{37568,68773,74917}
189893
Returns: 6.781600141343863E-4
{58482,24593,96845}
{59046,59522,16704}
181685
Returns: 0.10720369834524436
{28206,79169,47842}
{17702,40276,40728}
136611
Returns: 0.08354008553831994
{44128,58072,1558}
{17950,78496,58879}
181446
Returns: 0.1253451454565586
{79758,16033,47566}
{27921,38,70588}
75569
Returns: 0.0
{94277,47850,15363}
{55104,254,14554}
11603
Returns: 0.0
{59775,31257,93174}
{15793,12772,68827}
217980
Returns: 0.7859939081949852
{78513,37366,28649}
{50452,95438,30206}
316844
Returns: 0.9998928982662924
{76279,16897,28849}
{58382,32929,76414}
263751
Returns: 0.9246077149484246
{32967,74813,79603}
{55055,50474,94965}
34168
Returns: 0.0
{50728,37330,54464}
{12848,68587,75449}
205980
Returns: 0.188604746510523
{9170,46621,15412}
{15494,83987,44060}
2867
Returns: 0.0
{81770,2078,36692}
{85860,18974,91007}
260854
Returns: 0.558004158004158
{51902,69766,86167}
{12680,46925,93581}
198611
Returns: 0.05006851005720723
{97398,18704,8049}
{75937,56033,62513}
292407
Returns: 0.8680603183574588
{152,75399,858}
{27984,78056,29360}
158405
Returns: 0.2984124457884057
{365,46018,878}
{30671,32862,85957}
124207
Returns: 0.0
{132,78789,541}
{86885,92271,67799}
78593
Returns: 0.0
{473,80450,558}
{47753,6213,18347}
52038
Returns: 0.0
{244,61590,330}
{68195,39335,93173}
121734
Returns: 0.0
{184,24878,745}
{64484,70895,49948}
198154
Returns: 0.49692499397057643
{278,38250,761}
{80038,44851,6985}
30691
Returns: 0.0
{451,2596,855}
{90288,83045,85253}
39221
Returns: 0.0
{217,47850,629}
{55104,254,14554}
84319
Returns: 0.2922466039707419
{417,16897,533}
{58382,32929,76414}
176529
Returns: 0.4929277386518317
{98765, 87654, 76543 }
{1, 1, 1 }
200000
Returns: 0.9372135273032745
{500, 10000, 7000 }
{10, 10, 10 }
100
Returns: 1.6333333333333301E-6
{100000, 100000, 100000 }
{59999, 65432, 39999 }
379877
Returns: 0.895635095766732
{99999, 99999, 99999 }
{99999, 99999, 99999 }
99999
Returns: 0.0
{2, 100, 1 }
{9, 10, 8 }
50
Returns: 0.215
{0, 0, 2 }
{1, 1, 1 }
4
Returns: 0.5
{0, 200, 0 }
{1, 1, 1 }
100
Returns: 0.485
{345, 265, 456 }
{100, 100, 100 }
756
Returns: 0.34574130042999895