CF734D.Anton and Chess
普及+/提高
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.
The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.
Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move.
Help Anton and write the program that for the given position determines whether the white king is in check.
Remainder, on how do chess pieces move:
- Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.
- Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.
- Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap".
安东喜欢下棋,也喜欢编程。因此,他决定编写一个下棋程序。然而,他认为标准的 8×8 棋盘过于简单,于是改用无限大的棋盘。
他面临的第一个任务是判断国王是否处于“被将军”(check)状态。安东不知道如何实现这一功能,于是请你帮忙。
考虑一个无限大的棋盘,上面有一个白方国王和若干黑方棋子。目前仅支持车(rook)、象(bishop)和后(queen),其他棋子暂不支持。若至少有一枚黑方棋子能在一步之内到达白方国王所在的格子,则称该白方国王处于“被将军”状态。
请帮助安东编写一个程序:给定棋盘上各棋子的位置,判断白方国王是否处于被将军状态。
各棋子的走法回顾如下:
- 象(Bishop):可沿任意一条对角线移动任意格数,但不能越过任何被占据的格子;
- 车(Rook):可沿水平或垂直方向移动任意格数,但不能越过任何被占据的格子;
- 后(Queen):可沿水平、垂直或任意对角线方向移动任意格数,但不能越过任何被占据的格子。
输入格式
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.
The second line contains two integers _x_0 and _y_0 ( - 109 ≤ _x_0, _y_0 ≤ 109) — coordinates of the white king.
Then follow n lines, each of them contains a character and two integers x__i and y__i ( - 109 ≤ x__i, y__i ≤ 109) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.
输入的第一行包含一个整数 n(1≤n≤500000)—— 黑色棋子的数量。
第二行包含两个整数 x0 和 y0(−109≤x0,y0≤109)—— 白方国王的坐标。
随后是 n 行,每行包含一个字符及两个整数 xi 和 yi(−109≤xi,yi≤109)—— 第 i 个棋子的类型及其位置。字符 'B' 表示象(主教),'R' 表示车(城堡),'Q' 表示后(皇后)。保证任意两个棋子不占据同一位置。
输出格式
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
输出的唯一一行应包含“YES”(不带引号),如果白方王处于被将军状态;否则包含“NO”(不带引号)。
输入输出样例
输入#1
2 4 2 R 1 1 B 1 5
输出#1
YES
输入#2
2 4 2 R 3 3 B 1 5
输出#2
NO
说明/提示
Picture for the first sample:

White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "YES".
Picture for the second sample:

Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "NO".
第一个样例的示意图:

白方国王处于被将军状态,因为黑方主教可在一步之内到达白方国王所在的格子。答案为“YES”。
第二个样例的示意图:

此处主教无法到达白方国王所在的格子,因为其行进路线被车阻挡,而主教不能“越过”其他棋子。车也无法到达白方国王所在格子,因为它不能沿对角线移动。因此,国王未被将军,答案为“NO”。
输入解题思路,AI测评打分。不知道怎么写?