Statistics

Problem Statement for "TnsBalls"

Problem Statement

PROBLEM STATEMENT

Your great-great-great-great-great-great grandfather just died (Man, was he
old!) and left you his inheritance.  Unfortunately, the only thing he left you
(having been a tennis champ in his day) was a humongous pile of tennis balls.
You don't want to throw away your inheritance, however useless it is to you, so
you decide to reserve a corner of your garage for the tennis balls.  Being
short on space, you want to find the most efficient way to store them.  You
decide to stack them in rectangular layers, one on top of the other.

Because of the nature of spheres (one cannot rest perfectly on top of another),
each complete layer must have a length that is one less than the length of the
layer beneath, and a width that is one less than the width of the layer
beneath, so that each tennis ball rests on four other tennis balls.  All layers
must be complete rectangles except for the top one, since the top layer will
not support other tennis balls.

For example, supposed the base of the stack has a length of 4 and a width of 3.
The bottom layer will look like this from above (each * represents a tennis
ball):

* * * *
* * * *
* * * *

The second layer from the bottom will look like this:

 * * *
 * * *

The third layer from the bottom will look like this:

  * *

Since the length of the third layer is 1, no layers can rest on top of it, so
the structure can hold at most 20 tennis balls.

Create a class TnsBalls that contains the method dimensions, which takes one
int, tballs, and returns an int[] with two elements representing the two
dimensions (in ascending order) of the bottom layer of the rectangular-based
structure that requires the least area yet safely holds all of the tennis balls.

DEFINITION
Class: TnsBalls
Method: dimensions
Parameters: int
Returns: int[]
Method signature (be sure your method is public): int[] dimensions(int tballs);

NOTES
- When stacking the tennis balls, no layer may contain holes or gaps.
- The top layer of the stack need not be a complete layer.  All of the rest
must be complete.
- If two sets of valid dimensions result in equal area, return the one in which
the width and length are closest together, so that the base of the stack will
appear more square than rectangular.
- Each layer in the structure must have a height of exactly one tennis ball.
- In the example diagrams, each * represents one tennis ball.

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
- tballs will be between 1 and 1000, inclusive.

EXAMPLES

=====================
Example 1: tballs = 1
=====================
The method returns {1, 1}
The bottom (and only) layer holds 1 tennis ball.

=====================
Example 2: tballs = 3
=====================
The method returns {1, 3}
The bottom (and only) layer holds 3 tennis balls.

======================
Example 3: tballs = 10
======================
The method returns {2, 4}
The bottom layer holds 8 tennis balls.
The second layer from the bottom holds 2 tennis balls.

=======================
Example 4: tballs = 127
=======================
The method returns {6, 8}
The bottom layer holds 48 tennis balls.
The second layer from the bottom holds 35 tennis balls.
The third layer from the bottom holds 24 tennis balls.
The fourth layer from the bottom holds 15 tennis balls.
The fifth layer from the bottom holds 5 tennis balls.

=======================
Example 5: tballs = 960
=======================
The method returns {12, 16}
The bottom layer holds 192 tennis balls.
The second layer from the bottom holds 165 tennis balls.
The third layer from the bottom holds 140 tennis balls.
The fourth layer from the bottom holds 117 tennis balls.
The fifth layer from the bottom holds 96 tennis balls.
The sixth layer from the bottom holds 77 tennis balls.
The seventh layer from the bottom holds 60 tennis balls.
The eighth layer from the bottom holds 45 tennis balls.
The ninth layer from the bottom holds 32 tennis balls.
The tenth layer from the bottom holds 21 tennis balls.
The eleventh layer from the bottom holds 12 tennis balls.
The twelfth layer from the bottom holds 3 tennis balls.

Definition

Class:
TnsBalls
Method:
dimensions
Parameters:
int
Returns:
int[]
Method signature:
int[] dimensions(int param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: