Curses Programming

alexander bookredwu at
Wed Nov 10 15:42:44 CET 2010

Hi, all

     Here is the test. Plz help.....

     If you use the new image search of Google, you will find that the
result images are layouted in a way that each row has the same height,
but contains different number of images dependents the width-height
ratio of each image. The goal is to make each row of images having
approximately same total width. Just try search any image, you will get the idea.
If you're the programmer designing this page, what algorithm would you
use to select images for each row?
The input of the program is a plain text file, each line in the file
containg 2 numbers, describing the width and height of an image
800 600
640 400
720 1280
Design an algorithm to put those images into a number of rows, each
row is 150 pixel height and 1200 pixel wide. You could scale images
proportionally to the same height. You need make sure the images are
aligned as closely as possbile to the row boundary.
The indexes of the images you would put on each row followed by blank
 According to the input file example, this output means image-0 (800 x
600) and image-1 (640 x 400) is put on the first row and image-2 (720
x 1280) is put on the second row.
Assuming, the input file contains less than 100 lines. Your algorithm
should finish within 5 secs on a standard laptop.


Could any give a hand?
Thanks a lot

More information about the Python-list mailing list