| Cut the board in three regions of the same area, traversable by a rook | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Complexity (1-100): 25
Three squares on a board M×N
are marked. Cut the board in three regions of the same area, each
containing a marked square and traversable by a rook (i.e. all squares
in a reagion share a side with at least one another). Example:
The input data are given in a file of the following format:
where M and N are the width and height of the matrix, (xi,yi) are the column and row numbers of marks, Tests 1. Input data: 9 9 4 4 4 5 4 6 A solution (may be more solutions): 2 2 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 2 2 2 1 1 3 3 3 1 2 2 2 1 1 3 3 3 1 2 2 2 2 2 3 3 3 1 2 2 2 3 3 3 3 3 1 2 2 3 3 3 3 3 3 1 2 2 3 3 3 3 3 1 1 2 2 2 3 3 1 1 1 1 2. Input data: |
|||||||||||
| Solution: | Solution.pas | ||||||||||
Page: 1
| Author | Post |
|---|---|
|
#1 Tue Jun 17, 2008 10:46 pm
|
|
|
Administrator
Registered: Jun 2008
Posts: 2
|
The Solution.pas is self-explanatory: everything is in comments. But I must admit that the solution is far from optimal: it checks all possible traversals over a region. We should add some additional checks in the backtracking mechanism.
|
Page: 1
Book of programming problems is powered by UseBB 1 Forum Software | Contact Admin