#P7589. 黑白棋(2021 CoE-II B)
黑白棋(2021 CoE-II B)
Description
and are playing a game called “Reversi”. The rules are as follows.
-
The game is played on the Cartesian coordinate plane.
-
uses black pieces, and uses white pieces.
-
Initially, choose any lines parallel to the axis on the coordinate plane. Their intercepts on the axis are all integers and are pairwise distinct. On each line, places one black piece, and places one white piece. The coordinates of all pieces are integers. The two pieces on the same line are not at the same position.
-
and take turns to move, and always moves first. On each turn, a player first chooses a line, then moves their own-colored piece on that line along the line.
-
A player may move their piece several integer units in one move toward the opponent’s piece; this is called forward. A player may also move their piece several integer units in one move away from the opponent’s piece; this is called backward.
As long as a forward move does not pass over the opponent’s piece and does not make the black and white pieces overlap, there is no limit on how far the piece can move forward. However, the forward distance must be at least . If the above conditions cannot be satisfied, the player cannot make a forward move.
To avoid the game never ending due to repeated backward moves, in a single game, the total number of backward moves performed by a player cannot exceed . Meanwhile, to prevent the game area from becoming too large and inconvenient to display, the distance of each backward move must be at least and at most . If the above conditions cannot be satisfied, the player cannot make a backward move. -
When it is a player’s turn, if they can make a move, they must make exactly one move. This move can be a forward move or a backward move (if the limit on the number of backward moves has not been exceeded).
-
If a player cannot make any move to move their piece, they lose and the game ends.
Given the initial state of the game, assuming that and both play optimally, determine whether can win.
Input Format
The input contains multiple test cases.
The first line contains an integer , the number of test cases. Then there is a blank line. Next are test cases describing the initial states.
For each test case, the first line contains three integers , , , representing the number of lines, the total allowed number of backward moves, and the maximum distance of each backward move. Then follow lines, each containing three integers , , , representing the intercept of the -th line, and the coordinates of the black piece and the white piece on that line, respectively ().
There is a blank line between every two test cases.
Output Format
If can win, output Yes; otherwise output No.
2
2 0 10
3 4 8
7 7 5
3 5 15
-3 -9 -19
-7 10 21
12 12 16
Yes
No
Hint
Sample Explanation
The figure below corresponds to the first test case of Input #1. If uses an optimal strategy, no matter how moves, can win.

Below is ’s winning strategy. First, chooses the line and moves the black piece from 4 to 6, so that the distance between the black and white pieces on both lines becomes . Since is , backward moves are essentially not allowed. If chooses to move the white piece on the line , then the two pieces on that line will become adjacent and cannot be moved afterward. Similarly, if chooses to move the white piece on the line , the two pieces on that line will also become adjacent and cannot be moved afterward. Therefore, no matter what does, one line will always end up with two adjacent pieces that cannot be moved anymore, while on the other line the distance between the pieces is and can still be moved once. then moves the remaining movable black piece by one more step. After that, cannot move any white piece, so wins.
For the second test case of Input #1, no matter how moves, can always win.
Constraints
For of the testdata, , , , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号