Knight Game
Hello everyone.
I´m raising this topic as I´m questioning why my answer is correct.
The description of the exercise is as follows.
Chess is the oldest game, but it is still popular these days. For this task we will use only one chess piece – the Knight.
The knight moves to the nearest square but not on the same row, column, or diagonal. (This can be thought of as moving two squares horizontally, then one square vertically, or moving one square horizontally then two squares vertically— i.e. in an "L" pattern.)
The knight game is played on a board with dimensions N x N and a lot of chess knights 0 <= K <= N2.
You will receive a board with K for knights and '0' for empty cells. Your task is to remove a minimum of the knights, so there will be no knights left that can attack another knight.
Input
On the first line, you will receive the N size of the board
On the next N lines, you will receive strings with Ks and 0s.
Output
Print a single integer with the minimum number of knights that needs to be removed
Constraints
- Size of the board will be 0 < N < 30
- Time limit: 0.3 sec. Memory limit: 16 MB.
Examples
Input |
Output |
5 0K0K0 K000K 00K00 K000K 0K0K0 |
1
|
2 KK KK |
0 |
8 0K0KKK00 0K00KKKK 00K0000K KKKKKK0K K0K0000K KK00000K 00K0K000 000K00KK |
12 |
My solution is as listed: https://pastebin.com/rpezzFpb
As there seems to be more to this exercise than just finding relations between pieces, I do not believe my answer should be right.
However, I also believe that if the issue is with the exercise itself, the scope of the exercise would be way too complicated to solve.
I can see how it would be handled by creating sub-matrixes and calculating between them to calculate the minimum amount of moves necessary to solve the problem.
I´d appreciate your thoughts!
EDIT: I seem to have forgotten to remove the PrintMatrix function that I used for debugging which is not part of the output.
As such, please disregard that part.
This was only created so I could make it convenient for myself to graphically see what my program was doing.