Problem Statement
Definition
- Class:
- RaceManagement
- Method:
- getPayoutFactor
- Parameters:
- int[], int[], int
- Returns:
- double
- Method signature:
- double getPayoutFactor(int[] probability, int[] amounts, int minimumMoney)
- (be sure your method is public)
Notes
- The returned value must have an absolute or relative error less than 1e-9.
Constraints
- probability will contain between 1 and 5 elements, inclusive.
- Each element of probability will be between 0 and 100, inclusive.
- Each element of amounts will be between 0 and 1000, inclusive.
- amounts will contain the same number of elements as probability.
- The sum of all the elements in probability will be at most 100.
- minimumMoney will be between 0 and 1000, inclusive.
Examples
{30}
{100}
10
Returns: 2.0
Horse 1 has a 30% chance of winning. If it wins, the company has to pay out 100*P dollars, where P is the payout factor, and if it doesn't win, the company gains 100 dollars. Thus, the expected earnings of the compay is 70-30*P. The highest payout factor that ensures this is at least 10 is 2.
{50,40}
{300,200}
100
Returns: 2.076923076923077
Horse A has a 50% chance of winning and horse B has a 40% chance of winning. But this also means that there is a 20% chance they tie and a remaining 30% chance neither of them wins. Thus, in this scenario, 4 cases arise Horse A wins 30% chance => The company loses 300*P dollars and gains 200 dollars Horse B wins 20% chance => The company loses 200*P dollars and gains 300 dollars Horse A & B both win (tie) 20% chance => The company loses 0*P dollars and gains 500 dollars Neither Horse A nor horse B wins (No result) 30% chance => The company loses 0*P dollars and gains 500 dollars To ensure the expected earnings are at least 100, the payout factor P can be at most approximately 2.077.
{10,10,10}
{100,100,100}
12
Returns: 10.851851851851851
{30,20,10}
{100,200,300}
100
Returns: 6.861635220125786
{50}
{100}
1000
Returns: -1.0
Return -1 because the payout factor in this case will be negative.
{0}
{100}
100
Returns: -2.0
The payout factor is irrelevant. The company always gains 100 dollars.
{0}
{100}
200
Returns: -1.0
{100}
{100}
100
Returns: -1.0
{100}
{0}
100
Returns: -1.0
{100}
{100}
10
Returns: -1.0
{49,31,3,3}
{637,361,549,601}
388
Returns: 5.5642566807308
{91,9,0,0,0}
{745,811,481,941,903}
181
Returns: 4.93420791796551
{34,65,0}
{621,729,86}
188
Returns: 2.2278088144009933
{56,14,29,1,0}
{604,548,839,764,236}
817
Returns: 5.764322718740284
{37,30,28,4,1}
{863,188,796,614,96}
511
Returns: 6.341439206765301
{21,59}
{105,660}
287
Returns: 0.5094744786707782
{91,9}
{241,655}
147
Returns: 2.655841341366748
{80,12,1,7,0}
{315,363,215,46,702}
310
Returns: 5.245643792496961
{97,0,2,0,1}
{641,55,827,299,840}
349
Returns: 2.8296004811766347
{9,18,29,18,4}
{323,5,157,256,690}
209
Returns: 15.088961223920425
{52,38,5,2,1}
{874,739,312,65,707}
325
Returns: 5.069966826773921
{0,0,0,0}
{100,100,100,100}
350
Returns: -2.0
{20,20,20,20,20}
{10,10,10,10,10}
1000
Returns: -1.0
{50,50}
{10,10}
500
Returns: -1.0
{1,1,1,1,1}
{500,500,500,500,500}
750
Returns: 71.87142489796517
{0,100,0,0}
{100,0,200,500}
450
Returns: -2.0
{0,50,0,0,50}
{10,0,20,70,0}
370
Returns: -1.0
{0,0,100,0,0}
{0,0,180,0,0}
950
Returns: -1.0
{0,0,30,0,50}
{0,0,70,0,80}
100
Returns: 0.2987012987012987
{0,0,0,0,100}
{0,0,0,0,40}
50
Returns: -1.0
{20,20,1,20,1}
{10,500,10,10,500}
70
Returns: 13.155002944240612
{100}
{20}
100
Returns: -1.0
{100}
{0}
50
Returns: -1.0
{0}
{0}
60
Returns: -1.0
{0}
{170}
50
Returns: -2.0
{0}
{890}
420
Returns: -2.0
{50, 40 }
{300, 200 }
100
Returns: 2.076923076923077
{20, 18, 14, 32, 12 }
{140, 200, 180, 120, 320 }
294
Returns: 8.47036366123654
{15, 16, 17, 18, 19 }
{29, 28, 27, 26, 25 }
50
Returns: 6.837560730100021
{100 }
{0 }
101
Returns: -1.0
{10, 50, 5, 15, 19 }
{60, 100, 25, 75, 105 }
50
Returns: 6.337901176815901
{0 }
{100 }
120
Returns: -1.0
{0, 10, 30, 20 }
{0, 0, 0, 0 }
10
Returns: -1.0
{0 }
{100 }
101
Returns: -1.0
{25, 24, 23, 12, 10 }
{111, 222, 333, 444, 555 }
987
Returns: 4.9323538208695
{10, 10, 33, 44, 1 }
{166, 266, 366, 466, 566 }
666
Returns: 5.44652321557496
{20, 30, 40 }
{100, 100, 100 }
100
Returns: 3.424778761061947
{30, 20, 15, 35 }
{100, 50, 20, 60 }
10
Returns: 6.79713278162712
{34, 12, 22, 11 }
{100, 333, 222, 11 }
15
Returns: 9.034966967256441
{0 }
{50 }
100
Returns: -1.0
{30, 13, 35, 2, 3 }
{0, 0, 1, 1, 999 }
133
Returns: 72.33154747359897
{0 }
{100 }
100
Returns: -2.0
{0 }
{100 }
110
Returns: -1.0
{0 }
{0 }
1
Returns: -1.0
{50 }
{100 }
1000
Returns: -1.0
{0, 0 }
{0, 0 }
1
Returns: -1.0
{0, 100 }
{20, 20 }
10
Returns: 0.5
{10, 50, 5, 10, 10 }
{100, 200, 300, 400, 500 }
250
Returns: 10.04264670156143
{0, 0, 0 }
{10, 10, 10 }
1000
Returns: -1.0
{30, 20, 10, 20, 6 }
{300, 800, 250, 30, 150 }
900
Returns: 3.451335457162043
{0, 100 }
{100, 0 }
200
Returns: -1.0
{0 }
{10 }
100
Returns: -1.0
{0 }
{100 }
1000
Returns: -1.0
{100 }
{0 }
1000
Returns: -1.0