Problem Statement
Structural integrity provides some constraints on your design. The support area of a box (other than the bottom box) is defined to be the common area between it and the box below it. The following 2 rules must be satisfied.
- The "overhang" rule" says that no point on the bottom of a box may be more than a distance of 50 from the box's support area. Here the crucial distance is the distance between a bottom corner of a box and the corresponding upper corner of a smaller box on which it rests.
- The "strength rule" says that each box's support area must be big enough to support the volume of the box (its width times its length times 10) and of all the boxes above it. The total volume that can be supported by an area is K*area. The strength rule does not apply to the bottom box which rests on the ground.
XXXXX
YYY
ZZZZZZZZZZZZZ
QQQQQQQQQQQ
Our design goal is to make the top floor (the roof) have as large an area as
possible for our helipad and roof gardens. It may even be larger than our lot.
Create a class Architect that
contains a method roofArea that is given width, length, n, and K and that
returns the area of the largest roof possible. Return -1 if no building meets
all the requirements.
Definition
- Class:
- Architects
- Method:
- roofArea
- Parameters:
- int, int, int, int
- Returns:
- double
- Method signature:
- double roofArea(int width, int length, int n, int K)
- (be sure your method is public)
Notes
- Your return value must have an absolute or relative error less than 1e-9.
Constraints
- width and length will be between 1 and 5000, inclusive.
- n will be between 1 and 100, inclusive.
- K will be between 1 and 10000, inclusive.
Examples
1000
1000
2
5
Returns: -1.0
This building has just 2 boxes. The only support requirement is that the area between them must be enough to support the volume of the top box. But K is so low that the area of the bottom of a box cannot support its own volume, so no building meets the requirements.
1000
1000
1
5
Returns: 1000000.0
This building is a single box, supported by the ground. Its size must be 1000 x 1000 to match the width and length of the lot.
6
8
2
3000
Returns: 5808.0
Here the overhang rule determines the size of the top box. The horizontal distance from the center to a corner of the bottom box is 5. So the top box can have its corner 55 from the center. So it can be 11 times as big linearly, and its area would then be 11*11*(6*8) = 5808. K is large enough so that the support area of 48 can support the 58080 volume of the top box.
100
200
3
40
Returns: 52489.99599679679
The design is (approximately) 100 x 200 = 20,000 on the bottom, 117.28 x 234.56 = 27,510 in the middle, and 162 x 324 = 52,490 on top. The bottom box can then just barely support the top 2 boxes, since their volume is 10*27,510 + 10*52,490 = 800,000 which requires a support area of 800,000/40 = 20,000. The top box is easily supported by the box under it, but just barely satisfies the overhang rule. The horizontal distance from the center to one of its corners is 131.125 while the distance from the center to a corner of the top box is 181.125, an overhang of 50.
1000
1000
100
10000
Returns: 3.457271320057437E7
1
1
100
11
Returns: 3.944304526105059E-31
10
10
10
300
Returns: 2287.3635709236396
10
10
1
10
Returns: 100.0
10
10
2
10
Returns: 100.0
5000
5000
3
10
Returns: -1.0
5000
5000
100
10
Returns: -1.0
1
1
10
11
Returns: 5.131581182307066E-9
1
1
100
11
Returns: 3.944304526105059E-31
4999
3
10
75
Returns: 13575.230351140042
1
1
100
10000
Returns: 906.6044494080761
5000
4999
100
10000
Returns: 1.4399656894988048E8
5000
5000
100
10000
Returns: 1.440085713374673E8
17
111
7
12
Returns: 0.29120370370370363
1162
3599
62
2667
Returns: 2.8552464655759886E7
3843
250
54
3415
Returns: 5424808.2075312305
3127
553
39
2633
Returns: 8344037.218917707
2761
3006
99
3482
Returns: 7.078527407258719E7
4572
4883
76
3860
Returns: 1.0045066826889175E8
2603
2074
35
1348
Returns: 2.206269237523116E7
3312
620
81
714
Returns: 4502116.1450331565
1789
3753
6
7054
Returns: 8426130.173917074
4874
4846
14
1854
Returns: 3.3399280047233723E7
1315
3333
61
9458
Returns: 3.1352029624960594E7
3957
1222
91
6432
Returns: 4.868859296954085E7
3646
587
49
170
Returns: 587352.8191156008
3694
114
51
9557
Returns: 2331360.817861364
4709
3027
95
9317
Returns: 1.0231603615957418E8
347
2169
90
8645
Returns: 1.8006254753502868E7
670
1254
75
5970
Returns: 2.0525545577459134E7
2035
4302
82
8167
Returns: 6.3916590328182146E7
4556
4774
31
9683
Returns: 4.602114915307121E7
2754
1629
15
166
Returns: 7247602.338271659
3727
368
74
4331
Returns: 1.1929328990457427E7