D. Anton and Chess

题目连接:

http://codeforces.com/contest/734/problem/D

Description

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".

Input

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.

Output

The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.

Sample Input

2

4 2

R 1 1

B 1 5

Sample Output

YES

Hint

题意

一个无限大的平面,给你一个King的位置,再给你其他棋子的位置,问你这个King是不是正在被人将军。

题解:

只用考虑King的八个方向最近的棋子是什么就好了,记录一下就行了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+6;
long long x[maxn],y[maxn],xx,yy;
char a[3][3];
long long dis[3][3];
string s;
int f(int x){
if(x==0)return 1;
if(x>0)return 2;
if(x<0)return 0;
}
int main()
{
int n;scanf("%d",&n);
scanf("%lld%lld",&xx,&yy);
for(int i=0;i<3;i++)for(int j=0;j<3;j++)dis[i][j]=2e15,a[i][j]='W';
for(int i=1;i<=n;i++){
cin>>s>>x[i]>>y[i];
x[i]-=xx,y[i]-=yy;
if(x[i]!=0&&y[i]!=0&&abs(x[i])!=abs(y[i]))continue;
if(dis[f(x[i])][f(y[i])]>max(abs(x[i]),abs(y[i]))){
dis[f(x[i])][f(y[i])]=max(abs(x[i]),abs(y[i]));
a[f(x[i])][f(y[i])]=s[0];
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(a[i][j]=='Q')return puts("YES");
if((i+j)%2==0&&a[i][j]=='B')return puts("YES");
if((i+j)%2==1&&a[i][j]=='R')return puts("YES");
}
}
puts("NO");
}

Codeforces Round #379 (Div. 2) D. Anton and Chess 水题的更多相关文章

  1. Codeforces Round #379 (Div. 2) D. Anton and Chess —— 基础题

    题目链接:http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test 4 seconds me ...

  2. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  3. Codeforces Round #379 (Div. 2) A. Anton and Danik 水题

    A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...

  4. Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟

    题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmem ...

  5. Codeforces Round #404 (Div. 2) B. Anton and Classes 水题

    B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...

  6. Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题

    A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...

  7. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  8. Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟

    A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

随机推荐

  1. Python-pycharm

    进入博客园的第一篇随笔,作为一个编程菜鸟,最近在学习Python,为毕设做准备.总觉得Python自带的idle不太好用,一位“大鸟”向我推荐了pycharm,于是我就抱着试试看的态度下了一个,目前感 ...

  2. linux(ubuntu)安装时遇到的问题

    window环境下安装linux虚拟机=时,由于在初始系统语言选择了中文,当linux虚拟机安装成功后, 按[Ctrl + alt +f1~f6]任一一键都行,进入到命令行模式,这时你会发现,哎,我的 ...

  3. iOS 汉字转拼音

    - (NSString *)getFirstString:(ICCustom *)custom {     NSMutableString *source = [custom.merchantAbbr ...

  4. Windows 8.1 应用再出发 (WinJS) - 创建一个简单项目

    前面几篇我们介绍了如何利用 C# + XAML 完成Windows Store App 功能的实现,接下来的几篇我们来看看如何利用 Html + WinJS 来完成这些功能. 本篇我们使用WinJS ...

  5. C2第五次作业解题报告

    看过题解后如果觉得还算有用,请帮忙加点我所在团队博客访问量 http://www.cnblogs.com/newbe/ http://www.cnblogs.com/newbe/p/4069834.h ...

  6. python numpy 介绍

    NumPy提供了两种基本的对象:ndarray(N-dimensional array object)和 ufunc(universal function object).ndarray(下文统一称之 ...

  7. 【书海】《Head First Java》 ——读后总结

    <Head First Java> 中文版 (第二版) IT`huhui前言录 <Head First Java>这本书我不算特别细的看了一遍.认为十分适合初学者,甚至是没接触 ...

  8. JS原型链简单图解

    JS中原型链,说简单也简单. 首先明确: 函数(Function)才有prototype属性,对象(除Object)拥有__proto__. 首先,我画了一张图. 所谓原型链,指的就是图中的proto ...

  9. nosql/nodejs基础

    nosql定义:nosql--no only sql 目前流行的非关系型数据库:mongodb,redis,cassandra 非关系型数据库和内存存储hashmap数据结构有什么区别?hashmap ...

  10. atitit. access token是什么??微信平台公众号开发access_token and Web session保持状态机制

    atitit. access token是什么??微信平台公众号开发access_token and Web session保持状态机制 1. token机制and  session保持状态机制 1 ...