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 2422 Точки

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

1
nasyotbm avatar nasyotbm 5 Точки

nvm

0
07/06/2020 13:39:00
WobrGraboid avatar WobrGraboid 5 Точки

I'm looking for some kind of gambling game, but not card games. I generally don't like games like poker, blackjack and all that. I'm already tired of slots too. Is there any hope that I can find something new?

0
Catchy_Title avatar Catchy_Title 2 Точки

There are so many games now. I can't imagine how you can't find something new. Most gambling platforms now provide both classic and innovative games. But personally, I like Bitcoin dice https://duckdice.io/. On the one hand, this is something more than classic, but on the other, Bitcoin investments bring something new to the gameplay. There are also cool bonuses. Try it, maybe this is what you are looking for.

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.