| Problem 155 - All Squares, Explanations |
The straight-forward way will result in a Time-Limit exceeded, so let's think a little...
This problem involves zooming! Why continue drawing patterns in the left-bottom part while we know the point is in the right-upper part?
Draw the first square and let it call the same functions to draw it's childrens. Of course, do not call children if it's too far from the point.
Do not really draw... You can compute if it's in or out quite easily, without wasting memory!
If you are in trouble with the multi-entry input, read my how to read input.
Hence, given a value of k, we can draw a unique pattern of squares according to the above rules. Furthermore any point on the screen will be surrounded by zero or more squares. (If the point is on the border of a square, it is considered to be surrounded by that square). Thus if the size of the largest square is given as 15, then the following pattern would be produced.
Write a program that will read in a value of k and the coordinates of a point, and will determine how many squares surround the point.
Input will consist of a series of lines. Each line will consist of a value of k and the coordinates of a point. The file will be terminated by a line consisting of three zeroes (0 0 0).
Output will consist of a series of lines, one for each line of the input. Each line will consist of the number of squares containing the specified point, right justified in a field of width 3.
500 113 941 0 0 0
5