[Solution] Queen Blocks solution codechef

Table of Contents

Queen Blocks solution codechef

Queen Blocks solution codechef – You are given an 8\times 8 chessboard. Your enemy king is at point (X,Y) (1 \leq X,Y \leq 8).

You need to place some number of queen pieces on the chessboard such that the following conditions are satisfied:

  • The king should not be under attack by any of the queens that you have placed.
  • The king should not be able to make any move.

Note that a king can move one unit in any of the 8 direction while a queen can attack horizontally, vertically as well as diagonally.

Find the minimum number of queens required to satisfy the given conditions. Print the chessboard where 0 denotes empty cells, 1 denotes the king, and 2 denotes the queen(s) placed by you in some position(s).

Input Queen Blocks solution codechef

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line of each test case contains two space-separated integers A and B — the coordinates of the king.

Output Format

For each test case, output a 8\times 8 grid consisting of King, Queen(s) and blank cells.

Print the chessboard in 8 lines where each line has 8 space-separated integers where 0 denotes empty cells, 1 denotes the king, and 2 denotes the queen(s) placed by you in some position(s).

Queen Blocks solution codechef

  • 1 \leq T \leq 64
  • 1 \leq A,B \leq 8

Sample 1:

Input

Output

1
2 1
0 0 2 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

Queen Blocks solution codechef Explanation:

Test case 1: We can place 2 queens at (1, 3) and (3, 3) respectively. Thus, the king at (2, 1) has no safe squares to go to and is not under attack.

Queen Blocks solution codechef

For Solution

“Click Here”

Leave a Comment