Question: Java There are K knights on N x N chessboard and you are to determine how many squares they are guarding. Write a program that

Java

There are K knights on N x N chessboard and you are to determine how many squares they are guarding. Write a program that reads positive integers N and K and then K positions of knights, and prints the number of squares that are guarded by these K knights. A square is guarded if it is either occupied by a knight or is reachable by a knight by a single move. A knight move is always by two squares in one direction and by one square in perpendicular direction. E.g. by two squares in horizontal direction and by one square in vertical direction.

Java There are K knights on N x N chessboard and you

Example of input: 8 2 c 1 e 2

Corresponding output: 10

Example of input: 8 6 c 1 e 2 d 4 c 7 f 7 h 6

Corresponding output: 30

23 abcdefgh 87654321

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!