GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday, 24 August 2022

[Solution] Queen Blocks CodeChef Solution



Problem

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).

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Input Format

  • 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).


No comments:

Post a Comment