GUPTA MECHANICAL

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

Wednesday, 22 June 2022

[Solution] The Attack of Knight CodeChef Solution

While playing chess, Chef noticed that it is generally advantageous for him if his knight attacks two or more of his opponent's pieces simultaneously. To practice this skill, Chef decided to perform the following exercise:

  • Take an empty 8×8 chessboard, and any two white pieces.
  • Choose two distinct cells (X1,Y1)(X2,Y2) and place the pieces on those cells (the cell at the intersection of the i-th row and j-th column is denoted (i,j)).
  • Check if there exists an empty cell where he can place a black knight in such a way that the knight attacks both the white pieces simultaneously.

Given the position of the two white pieces (X1,Y1)(X2,Y2), print 'YES' if there exists an empty cell where he can place a black knight in such a way that the knight attacks both the white pieces simultaneously, otherwise print NO.

Solution Click Below:-  CLICK HERE


For reference, a knight attacks a piece placed in a cell that is:

  • One square horizontally and two squares vertically away from it, or
  • One square vertically and two squares horizontally away from it

A visual description of this may be found here.

Input Format

  • The first line of input will contain an integer T — the number of test cases. The description of T test cases follows.
  • The first line of each test case contains two space-separated integers X1 and Y1, the position of first white piece.

  • The second line of each test case contains two space-separated integers X2 and Y2, the position of second white piece.

Output Format

For each test case, output the answer on a new line — YES if there exists an empty cell where Chef can place a black knight in such a way that the knight attacks both the white pieces simultaneously, and NO otherwise.

You may print each character of YES and NO in either uppercase or lowercase (for example, yesyEsYes will be considered identical).

Constraints

  • 1T5000
  • 1X1,Y18
  • 1X2,Y28
  • Both the cells are distinct

No comments:

Post a Comment