A10767 | Anton and Chess
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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".
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".
输入格式
The first line of the input contains a single integer $n$ ( $1<=n<=500000$ ) — the number of black pieces.
The second line contains two integers $x_{0}$ and $y_{0}$ ( $-10^{9}<=x_{0},y_{0}<=10^{9}$ ) — coordinates of the white king.
Then follow $n$ lines, each of them contains a character and two integers $x_{i}$ and $y_{i}$ ( $-10^{9}<=x_{i},y_{i}<=10^{9}$ ) — 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.
The second line contains two integers $x_{0}$ and $y_{0}$ ( $-10^{9}<=x_{0},y_{0}<=10^{9}$ ) — coordinates of the white king.
Then follow $n$ lines, each of them contains a character and two integers $x_{i}$ and $y_{i}$ ( $-10^{9}<=x_{i},y_{i}<=10^{9}$ ) — 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.
输出格式
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
输入输出样例
输入 #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".
 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".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted