Falling Apples: Difference between revisions

From programming_contest
Jump to navigation Jump to search
imported>Kmk21
Created page with "This problem asks us to read an ascii grid of apples and obstacles, and push all the apples to their lowest position. Simple walk each column from bottom to top, maintaining..."
 
(No difference)

Latest revision as of 04:18, 7 November 2017

This problem asks us to read an ascii grid of apples and obstacles, and push all the apples to their lowest position.

Simple walk each column from bottom to top, maintaining a pointer to the first position higher than the last obstacle you have seen. When you find an apple, "move" it to the location of your pointer, and increment the pointer one position higher. When you find an obstacle, set the position of the pointer to the next spot.

There are 500k spots, so this should be plenty fast. Note that it is far easier to do this as a 50kx10 char array than as strings