Problem D
Rings
Dee Siduous is a botanist who specializes in trees. A lot of her research has to do with the formation of tree rings, and what they say about the growing conditions over the tree’s lifetime. She has a certain theory and wants to run some simulations to see if it holds up to the evidence gathered in the field.
One thing that needs to be done is to determine the expected
number of rings given the outline of a tree. Dee has decided to
model a cross section of a tree on a two dimenional grid, with
the interior of the tree represented by a closed polygon of
grid squares. Given this set of squares, she assigns rings from
the outer parts of the tree to the inner as follows: calling
the non-tree grid squares “ring
An example of this is shown in the figure below.
![\includegraphics[width=0.60\textwidth ]{ring}](/problems/rings2/file/statement/en/img-0001.jpg)
Figure D.1
Most of Dee’s models have been drawn on graph paper, and she
has come to you to write a program to do this automatically for
her. This way she’ll use less paper and save some
Input
The input will start with a line containing two positive
integers
Output
Output a grid with the ring numbers. If the number of rings is less than 10, use two characters for each grid square; otherwise use three characters for each grid square. Right justify all ring numbers in the grid squares, and use ‘.’ to fill in the remaining characters.
If a row or column does not contain a ring number it should still be output, filled entirely with ‘.’s.
Sample Input 1 | Sample Output 1 |
---|---|
6 6 .TT... TTTT.. TTTTT. TTTTT. TTTTTT ..T... |
...1.1...... .1.2.2.1.... .1.2.3.2.1.. .1.2.3.2.1.. .1.1.2.1.1.1 .....1...... |
Sample Input 2 | Sample Output 2 |
---|---|
3 4 TT.. TT.. .... |
.1.1.... .1.1.... ........ |