Problem Statement
R = K * ln(take-off mass / empty mass)
where K is a constant for the aircraft and the take-off mass is equal to the empty mass + the mass of fuel on board the aircraft. In addition, taking off and gaining altitude takes a certain, constant amount of fuel.
An airline wishes to minimize the amount of fuel consumed on a given journey by allowing the aircraft to stop at intermediate cities along the way to refuel. Assume that the aircraft can stop an unlimited number of times and can stop at any point of its journey. Also assume that it can carry an unlimited amount of fuel.
You will be given an
Definition
- Class:
- FlightScheduler
- Method:
- minimizeFuel
- Parameters:
- int, int, int, int
- Returns:
- double
- Method signature:
- double minimizeFuel(int distance, int K, int emptyMass, int takeoffFuel)
- (be sure your method is public)
Notes
- The return value must be accurate to within an absolute or relative tolerance of 1e-9.
Constraints
- distance will be between 1 and 200,000, inclusive.
- K will be between 1 and 200,000, inclusive.
- emptyMass will be between 1 and 200,000, inclusive.
- takeoffFuel will be between 1 and 200,000, inclusive.
Examples
40000
100000
150000
5000
Returns: 76420.82744805096
The optimal schedule here is to make 1 stop right in the middle of the flight.
40000
55000
150000
5000
Returns: 138450.61724934017
K is a measure of the efficiency of the aircraft. With this less efficient aircraft it's best to stop twice.
1000
500
1000
50
Returns: 2664.9853821314487
10000
100
200
5
Returns: 24635.869665316768
100000
50
600
2
Returns: 1299304.0427867468
150000
1
150000
1
Returns: 2.2582208368425556E10
12197
29451
12718
32501
Returns: 39026.31721326991
20607
28917
19654
19562
Returns: 39989.17092307296
29736
10528
25877
16975
Returns: 172324.12469702153
21058
23220
19183
1591
Returns: 25085.657435445617
30308
11772
25672
2519
Returns: 97520.36786129391
24768
25205
29304
18875
Returns: 67858.362827057
6659
8997
25915
25655
Returns: 54063.5346710648
15997
29998
24316
7327
Returns: 24457.500644322783
17538
29859
20051
7866
Returns: 23891.42563843786
528
21402
16588
5749
Returns: 6163.325586698862
132012
4092
141596
136500
Returns: 1.2252181131019197E7
31749
113800
105042
123282
Returns: 157083.82292453357
144012
2
149866
1
Returns: 1.0830696881014162E10
105600
53088
142186
9160
Returns: 390312.21653136547
80300
130743
140222
138212
Returns: 257140.48138689072
146078
6355
124698
105111
Returns: 7328605.984328408
84480
133200
105448
110262
Returns: 203644.394951216
12960
138322
115084
63960
Returns: 75264.02264476861
125131
56056
14100
142880
Returns: 260203.46807218198
112156
46368
24650
1848
Returns: 84157.96997191163
42768
144400
12298
127280
Returns: 131519.22553615
97539
131104
19200
97284
Returns: 118486.51986899413
131040
60800
115350
147130
Returns: 741290.5188633981
20184
12921
95700
111384
Returns: 449342.1451898261
145000
10980
103885
95985
Returns: 3624819.2190171042
129280
15200
133950
18624
Returns: 1790851.8724892882
146478
1
103432
4
Returns: 1.5283950796441101E10
147777
1
100000
1
Returns: 1.4843837124166306E10
140000
4
10000
10
Returns: 3.6576871282155204E8
127777
1
150000
1
Returns: 1.923657892461537E10
200000
1
200000
1
Returns: 4.012655775551904E10
99999
99999
99999
99999
Returns: 271825.4645640761
200000
1
100000
1
Returns: 2.0089509360950325E10
140000
1
10000
1
Returns: 1.4198456017490478E9
140000
4
10000
1
Returns: 3.5496140043726254E8
140000
1
200000
10
Returns: 2.828046627881105E10
200000
1
150000
1
Returns: 3.0109611157900635E10
20000
1
20000
1
Returns: 4.040066611258699E8
190000
1
10000
1
Returns: 1.926933316659421E9
200000
1
43243
1
Returns: 8.707483633296806E9
100000
1
100000
1
Returns: 1.0044754680475334E10
123567
12
123
1519
Returns: 1.1728119506754944E7
200000
1
200000
200000
Returns: 1.0873127313836182E11
200000
1
1
200000
Returns: 4.440495288922814E9