Curses Programming

r0g aioe.org at technicalbloke.com
Thu Nov 11 00:20:23 EST 2010


On 10/11/10 14:42, alexander wrote:
> 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
> inimages.google.com, you will get the idea.
> If you're the programmer designing this page, what algorithm would you
> use to select images for each row?
>   Input:
> 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
>   e.g.
> 800 600
> 640 400
> 720 1280
> ...
>   Goal:
> 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.
> Output:
> The indexes of the images you would put on each row followed by blank
> line.
> e.g.
> 0
> 1
> 2
>   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.
> Constraint:
> 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
> Alex


Alex,

At least try thinking about how you would solve the problem - that is 
after all the whole point of the exercise i.e. to think up an algorithm, 
not to code it in python. That part is your homework and nobody here 
will do it for you. Also, if you don't enjoy solving this kind of 
problem it's possible you are studying the wrong subject.

If you can think of a basic strategy to solve the above problem and can 
explain it in fairly plain english then I'm sure some people here will 
be happy to a) improve it and b) Help you if you are struggling to 
translate your concept into working python code.

Even then, it being a homework assignment you can't expect people to 
just give it to you on a plate. Expect homework assistance to be at 
least slightly oblique, it's for your own good. If you don't have to do 
any thinking yourself then you're not going to learn much either and 
next week you'll be right back where you were, pestering some other poor 
forum.

Good luck with it!

Roger.



More information about the Python-list mailing list