
-----------------------------------
Tony
Sat Mar 22, 2003 12:51 pm

CCC 2003 Stage1: J2: Picture Perfect
-----------------------------------
Roy has a stack of student yearbook photos. He wants to lay the pictures on a flat sufrace edge-to-edge to form a filled rectangle with minimum perimeter. All photos must by fully visible. Each picture is a square with dimentions 1 unit by 1 unit.
For example, he would place 12 photos in the following configuration, where each photo is indicated with an X

XXXX
XXXX
XXXX

ofcourse, he could orient them in the other direction, such as

XXX
XXX
XXX
XXX

which would have teh same perimeter, 14 units.

Your problem should be interactive. It should repeatedly read a positive integer C, the number of pictures to be laid out. For each input, it should print the smallest possible perimeter for a filled rectangle that is formed by laying alla the pictures edge-to-edge. Also print the dimensions of this rectangle.

You may assuem that there are less than 65,000 photos. An input value of C=0 indicated that the program should terminate.

Sample Session
Enter number of pictures:
100
Minumum perimeter is 40 with dimensions 10x10

Enter number of pictures:
15
Minumum perimeter is 16 with dimensions of 3x5

Enter number of pictures:
195
Minumun perimeter is 56 with dimensions 13x15

Enter number of pictures:
0

Solution by JSBN


%LARGER AMOUNTS OF PICTURES WILL REQUIRE MORE TIME FOR CALCULATION 
var C : int 
var z : int 
var t2 : int 
var d1 : int 
var d2 : int 

loop 

    put "Enter number of pictures" 
    get C 
    t2 := 65000 
    exit when C = 0 
    for i1 : 1 .. C 
        for i2 : 1 .. C 
            z := i1 * i2 

            if z = C then 
                if (i1 + i2) * 2 