Queen Game
Time limit1sMemory limit128 MB
Given N queens on an R by C board that move up, left, or up-left, decide if the first player wins with optimal play.
- Level
Medium7 of 10
- Topics
- Game theory, Math, Bit manipulation
- Solved
- No attempts yet
Problem
Queen Game is a two-player game played on an chessboard. Rows are numbered to from top to bottom, and columns to from left to right; the top-left cell is row , column .
queens are placed on the board. Several queens may occupy the same cell, and each cell can hold arbitrarily many queens.
The two players alternate turns. On your turn you choose one queen and move it in one of three directions:
- up,
- left, or
- diagonally up-left.
You may move it by any number of cells, but a queen can never leave the board. When a queen reaches row , column , that queen is removed from the board. The player who removes the last queen wins.
Given the board size and the positions of the queens, and assuming both players play optimally, write a program that decides whether the first player has a winning strategy.
Input
The first line contains the number of test cases .
For each test case, the first line contains three integers , , and (, , ).
Each of the next lines contains the position of one queen: the row number and the column number, separated by a space.
Output
For each test case, print YES on its own line if the first player has a winning strategy, and NO otherwise.