A chessboard
Practice
3.5 (57 votes)
Algorithms
Basics of greedy algorithms
Greedy algorithms
Problem
92% Success 8433 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
In this version of chess, only two kings pieces are placed on the chessboard. Initially, the coordinates of the first king piece are generated \((X_1,\ Y_1)\), it is placed on the chessboard at the generated position. Now, the coordinates of the second king piece are generated \((X_2,\ Y_2)\), it is placed on the chessboard at the generated position.
These pieces can be moved in a sequential manner, that is, one by one, starting from the first piece. Both the kings want to win if they can not, at least draw.
Rules
- The chessboard is a standard \(8\times 8\) board.
- The kings can move from one cell to another if they have an edge or corner in common.
- If the generated coordinates of the second king are exactly equal to the first, then the second king wins.
- Both players play optimally.
- The game is considered to be won by the first king piece if after it moves, then it can have the same coordinates as the second. The second king piece becomes the winner if after this piece is moved, then both kings have the same coordinates. The game is drawn if there is no possible ways for anyone to win if both the pieces are played optimally.
Input format
- The first line contains \(T\) denoting the number of test cases.
- The first line of each test case contains two space-separated integers denoting the row and column of the first king \((X_1,\ Y_1)\).
- The second line of each test case contains two space-separated integers denoting the row and column of the second king \((X_2,\ Y_2)\).
Output format
Print \(T\) lines. For each test case:
- In a single line, print 'FIRST' if the first king piece wins, print 'SECOND' if the second king piece wins, and print 'DRAW' if none of them wins.
Constraints
\(1 \leq T \leq 5000\)
\(1 \leq X_1,X_2,Y_1,Y_2\leq 8\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
9 votes
Tags:
Greedy AlgorithmsAlgorithmsStringBasics of Greedy Algorithms
2.Coprimes
Points:10
41 votes
Tags:
Ad-HocAlgorithmsCoprimeEasyGreedy Algorithms
Points:10
3 votes
Tags:
Greedy AlgorithmsBasics of Greedy AlgorithmsSortingAlgorithmsMerge Sort
Editorial