programming language
posted by Ryan .
can enyone help me figure this out...
Surface to Volume Ratio
Write a program to compute surface to volume ratio. We will be given the height, width, and depth of N cuboid, and determine the smallest surface to volume ratio among them.
Input
The first line of the input data consists of N, where 0 < N <= 1000. The next N lines contain the height, width, and depth of each cuboid. All the dimensions are between 1 and 50.
Output
You should output the smallest surface to volume ratio as "a/b". This number must be simplified, that is, a and b must be prime to each other.
Sample input
2
2 3 4
1 1 1
Sample output
13/6
Hint: You may find the following recursive definition of greatest common divisor (gcd) useful. Let a >¢ê > 0. If the reminder of dividing a by b is 0, then of course the gcd of a and b is b. If the reminder is nonzero number c, then the gcd of and b is equal to the gcd of b and c.

One approach, simple but with a caveat or two:
You need a double for "smallest absoulte ratio so far". Initialise it to something very big.
As you take in each line,
a) calculate the surface and the volume as two integers
b) calculate the absolute ratio as a double
c) if
the absolute ratio is bigger than the "smallest absolute ratio so far", ignore that line,
else
store your new "smallest absolute ratio so far" and the surface and volume integers
At end, reduce your two integers to their lowest terms by calculating out their prime factors and dividing by the ones they have in common.
Technically, there's a potential gotcha in using a double, since it's possible that two ratios are so close that a double doesn't have enough precision to distinguish between them. However, with dimensions only up to 50, I think you'll be safe.
Afterthought: the input could contain two identical lines, or lines that end up with identical answers, and if I were writing the test, I surely would put such identical lines in! That's OK, because the answer is the same. 
OK, my conscience nags me about that double.
To do it right, then instead of taking the lazy way of converting to doubles, and comparing, then:
if your current smallest is, say, 13/6
and your new line is, say, 27/13
you should do the comparison by finding a common denominator. You don't have to waste CPU cycles on finding the lowest; just multiply the denominators:
13 / 6 = 169 / 78
27 / 13 = 162 / 78
and then compare your numerators to test which is smaller.
Respond to this Question
Similar Questions

Math
A rectangular prism has a volume of 960cm. It's width, length, and height are in the ratio 3:5:8. A) Determine the dimensions of the prism B) What is the ratio of the left side to the front to the top of the prism by surface area? 
science
for the three cubes shown below, determine their surface area, volume and surface area to volume ratio. Then circle the one you believe would be the most efficient and write a summary stating why. 1.5 cm x 1.5 cm x 1.5 cm .5 cm x .5 … 
bio
How does the surface areatovolume ratio of a 1mm cube compare to the surface areato volume ratio of a 3mm cube? 
bio
3. For the three cubes shown below, determine their surface area, volume and surface area to volume ratio. Then, circle the one you believe would be the most efficient and write a summary stating why 
Biology
When cells increase in size, the surface area to volume ratio decreases. But which surface area to volume ratio is better to the cell as well as to the organism? 
science
1. For the three cubes shown below, determine their surface area, volume and surface area to volume ratio. Then, circle the one you believe would be the most efficient and write a summary stating why. 
math
the dimension of a cuboid are in the ratio 5:3:2.find total surface area ? 
algebra
Find the lateral surface of a cuboid whose length, breadth and height are in a ratio of 4:3;2 and volume of the cuboid is 5184 cubic metre. 
science
For this activity, we had to make cube shaped models to represent cells. Then we had to compare aurafve area, volume, and surface area to volume ratio (SA:V) between the cells. Cell A: length of one side=1cm Surface area= 6cm^2 Volume= … 
Science
For this activity, we had to make cube shaped models to represent cells. Then we had to compare surface area, volume, and surface area to volume ratio (SA:V) between the cells. Cell A: length of one side=1cm Surface area= 6cm^2 …