Problem Link : http://www.spoj.com/problems/YELBRICK/
To minimize the number of cubes formed:
Vol of cube = (Vol of individual cuboids)/no of cubes
It should be perfect cube...
Cubes could be formed when all sides of individual cuboids are divisble by same no. or the volume is perfect cube.
It could be thought of all sides of resultant cube must be equal(ofcourse)..
And we have to maximize the final volume(of all cubes) with minimum no of cubes . So , we must divide all sides by GCD( lowest no. which divides all the given nos. ) and then finally adding up the individual volumes..
Code: http://pastebin.com/UaScQUq8
To minimize the number of cubes formed:
Vol of cube = (Vol of individual cuboids)/no of cubes
It should be perfect cube...
Cubes could be formed when all sides of individual cuboids are divisble by same no. or the volume is perfect cube.
It could be thought of all sides of resultant cube must be equal(ofcourse)..
And we have to maximize the final volume(of all cubes) with minimum no of cubes . So , we must divide all sides by GCD( lowest no. which divides all the given nos. ) and then finally adding up the individual volumes..
Code: http://pastebin.com/UaScQUq8
No comments:
Post a Comment