#K15756. Garden Tree Planting
Garden Tree Planting
Garden Tree Planting
You are given a garden represented by a grid with a specified number of rows and columns, and an integer num_trees representing the number of trees you wish to plant. The objective is to plant the trees such that no two trees are adjacent horizontally or vertically.
In other words, if you mark a tree as T
and an empty cell as .
, then the trees must be placed so that no two T
's share an edge. The maximum number of trees that can be planted is given by the formula:
If the given num_trees exceeds this maximum, output IMPOSSIBLE
(without quotes). Otherwise, output the grid configuration.
Note: The tree-planting strategy is to iterate through the grid by taking every second cell starting at the top left corner (cell (0,0)) until all trees are planted.
inputFormat
The input consists of a single line containing three space-separated integers: rows
, columns
, and num_trees
.
outputFormat
If a valid configuration exists, output the garden grid where each row is printed on a separate line. Each cell is represented by either T
(tree) or .
(empty). If it is impossible to plant the given number of trees without violating the constraints, output IMPOSSIBLE
.
4 4 4
T.T.
....
T.T.
....
</p>