rook

fg
There are black rooks and white rooks randomly in the 100 by 100 arena. The rook can move on both horizontal and vertical without being blocked by the same color one. The rooks have a higher priority from left to right and from top to bottom. The Rocks with greater priority move firstly. Firstly, the rook find competitor in the row, then in the column. If the rook found the competitor, it would move to attack the competitor.
Collision of a black rook and white rook causes the destruction of both rooks without any trace, damage to other rooks.
The rooks will stop when no competitor within the area that they can move.
If any rook meet a rock, they can’t continue moving.
If all rooks are destroyed or stopped, the game is over. Please, write a function which returns the number of remaining rooks in the area after the match.

[Example]
If you look down the arena in the sky, you can see the picture below:
Rock is shown as red cell.
As a result, the return number should be 6 because there are 3 while rooks and 3 black rooks left.
[Input]
A total of 50 test cases are given.
Next line is N, the length of the chess map.
Next is the N x N number.
- Value ‘0’ : means empty space
- Value‘1’ : The white rooks.
- Value ‘2’ : The black rooks.
-Value ‘3’: Rock
[Output]
Print your answer for each of the 50 test cases. On the first line of each case, write ‘#x’ (‘x’ represents case number) and leave a space. Then, express answer.
1
5
1 0 3 0 0
0 3 0 2 0
0 3 1 0 1
1 0 2 0 0
1 0 2 0 2
2
10
c
[Output]
#1 3
#2 5

[Rules]
- Do Not use any external libraries including the standard ones
(“#include <stdio.h> (or something else)” is NOT allowed)
- The same “main.cpp (given below)” is used for the evaluation
- The arena size is 100 x 100 (The picture above is just for an example)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.