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 line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.
The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king.
Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 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.
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
2 4 2 R 1 1 B 1 5
YES
2 4 2 R 3 3 B 1 5
NO
Picture for the first sample:
Picture for the second sample:
题意:就是给你一个很大的棋盘,给你一个白棋的位置还有n个黑棋的位置,问你黑棋能否一步就吃掉白棋
给你如下规则
1.‘B‘只能对角线移动,而且不能越过其他黑棋。
2.’R‘只能上下左右移动,而且不能越过其他黑棋。
3.‘Q’既能对角线移动又能左右移动,但是不能越过其他黑棋。
思路:这是一道模拟题,看着很水其实思维还是不够严谨啊。。。
由于题目中说不能跳跃棋子,又让我们看看能不一步走到,那么我们就是需要在八个方向上 看离白棋最近的是什么,然后看八个方向上有没有
满足条件的,上下左右四个方向如果最近的为R 或者Q那么久可以,如果右上左上右下左下最近的是B或者Q那么就可以;
处理:在读取每一个黑棋的时候我们需要判断一下它与白棋的关系,如果x和y的差值相等就在对角线上;