Problem Statement
We can run multiple tests. Each test can test only a single pressure on a single container, and the result of a test is either that the container survived or was destroyed. If it survived it can be used in successive tests.
We must develop a testing protocol that uses no more than numTests tests and destroys no more than numDestroyed containers. The testing must determine whether or not the container can withstand 100.0, and if it cannot it must also estimate the critical pressure as accurately as possible. Given numTests and numDestroyed return the minimum absolute error we can guarantee in our estimate of critical pressure.
Definition
- Class:
- Destruction
- Method:
- minError
- Parameters:
- int, int
- Returns:
- double
- Method signature:
- double minError(int numTests, int numDestroyed)
- (be sure your method is public)
Notes
- A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
- numTests will be between 1 and 50, inclusive.
- numDestroyed will be between 1 and numTests, inclusive.
Examples
1
1
Returns: 50.0
If the one test is at a pressure lower than 100.0 and the container survives, we won't know whether or not the container can survive pressures greater than 100. So the one test must be at a pressure of 100.0. If the container does not survive the test, then we can estimate the critical pressure at 50.0, with a possible error of +- 50.0.
3
1
Returns: 16.666666666666664
First test pressure = 33.3333333. If the test container is destroyed, the estimate is 16.66666667 with an error of +-16.6666667. If the container survives the first test, we can run a second test at 66.666667. If the container is destroyed, our estimate is 50.0. Otherwise we run our last test at 100.0 to determine whether to estimate 83.33333 or to report that these containers can survive more than 100.0.
20
3
Returns: 0.03703703703704745
50
50
Returns: 4.440892098505072E-14
50
2
Returns: 0.039215686274512815
13
2
Returns: 0.5494505494506943
1
1
Returns: 50.0
44
12
Returns: 1.554047087654485E-9
21
11
Returns: 3.568138238242022E-5
14
10
Returns: 0.0031420850876672595
36
24
Returns: 7.382324806476522E-10
44
10
Returns: 1.464542463581321E-8
14
8
Returns: 0.0038729666924899302
3
3
Returns: 7.142857142863266
26
25
Returns: 7.450580818975891E-7
13
6
Returns: 0.01221001221002166
1
1
Returns: 50.0
27
1
Returns: 1.8518518518518527
7
5
Returns: 0.4201680672272863
33
16
Returns: 1.1641532185413996E-8
17
11
Returns: 4.1095102285749205E-4
43
37
Returns: 5.6843425964906114E-12
45
28
Returns: 1.4745024640935189E-12
45
45
Returns: 1.4210854715216623E-12
42
41
Returns: 1.1368683772178145E-11
17
14
Returns: 3.8192137002872025E-4
25
4
Returns: 0.0032733224222595892
42
17
Returns: 8.121757766089898E-11
35
17
Returns: 2.9103830458452908E-9
34
22
Returns: 2.996707201767642E-9
43
16
Returns: 9.002083370379123E-11
2
1
Returns: 25.0
32
31
Returns: 1.1641532188126137E-8
39
30
Returns: 9.096284521219955E-11
46
38
Returns: 7.105433864563008E-13
37
27
Returns: 3.6426472383792203E-10
2
1
Returns: 25.0
14
9
Returns: 0.003353004291848685
27
20
Returns: 3.73635856422665E-7
31
12
Returns: 1.6569128185640456E-7
20
3
Returns: 0.03703703703704745
11
8
Returns: 0.025252525252549913
50
30
Returns: 4.7216420002517887E-14
40
13
Returns: 2.363717064350744E-9
50
50
Returns: 4.440892098505072E-14
50
49
Returns: 4.4408920985050766E-14