Професионална програма
Loading...
+ Нов въпрос
JonHanes avatar JonHanes 0 Точки

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 rowcolumn, 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.

Тагове:
0
C# Advanced 24/01/2020 09:43:33
Axiomatik avatar Axiomatik 296 Точки

Hi Jon,

Just stumbled upon Knight Game a couple of weeks ago and my first reaction was that the solution lies into counting all the attack moves that each horse-unit can perform and remove for each iteration the most dangerous piece until there are no more pieces left on the board that can attack each other (this can be done by active/passive counting => how many pieces are targeted by one horse-unit or how many targets can attack one horse-unit).

I've also read from other colleagues that the solution lies in creating a recursion-logic that compares the effect of removing each piece on the board to discover the most optimal removing-pattern (ie the one that removes the fewest units from the board, but not necessarily a horse-unit with the highest attack-count), which I've also tinkered with but which failed the judge-system test. To my knowledge, recursions are introduced in C# OOP (or later?) so the solution to this exercise lies in just counting the offensive move of one horse-unit (and which is also demonstrated by the Softuni instructors).

Best,

Kristian

---

Hallo Jon,

Hab mir auch ziemlich lange den Kopf zerbrochen wie das Problem gelöst werden muss. Zuerst versucht das jeweilige Pferd zu entfernen, dass von den meisten gegnerischen Einheiten angegriffen werden kann, bis es keine Einheiten mehr gibt die sich gegeneinander angreifen können. Recursion-patterns sind jedenfalls nicht die Lösung, denn die kommen beim Judge-System nicht durch, obwohl manche Kollegen gezeigt haben dass nur diese die optimale/minimale Anzahl von Einheiten vom Brett entfernen. Von dem was ich weiss, kommen solche kompliziertere Probleme erst gegen Ende des Kurses.

Gruesse aus Bulgarien,

Kristian

0
nasyotbm avatar nasyotbm 5 Точки

nvm

0
07/06/2020 13:39:00