Anton and Chess
4 seconds
256 megabytes
standard input
standard output
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:
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".
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t;
set<pair<int,char> >a,b,c,d;
bool flag;
int main()
{
int i,j;
scanf("%d%d%d",&t,&n,&m);
rep(i,,t)
{
char str[];
scanf("%s%d%d",str,&j,&k);
if(j==n)a.insert(mp(k,str[]));
else if(k==m)b.insert(mp(j,str[]));
else if(n-j==m-k)c.insert(mp(j,str[]));
else if(n-j==k-m)d.insert(mp(j,str[]));
}
//
auto p=a.lower_bound(mp(m,'B'));
if(p!=a.begin())
{
p--;
if(p->se=='Q'||p->se=='R')flag=true;
p++;
}
p=a.upper_bound(mp(m,'B'));
if(p!=a.end())
{
if(p->se=='Q'||p->se=='R')flag=true;
}
//
p=b.lower_bound(mp(n,'B'));
if(p!=b.begin())
{
p--;
if(p->se=='Q'||p->se=='R')flag=true;
p++;
}
p=b.upper_bound(mp(n,'B'));
if(p!=b.end())
{
if(p->se=='Q'||p->se=='R')flag=true;
}
//
p=c.lower_bound(mp(n,'B'));
if(p!=c.begin())
{
p--;
if(p->se=='Q'||p->se=='B')flag=true;
p++;
}
p=c.upper_bound(mp(n,'B'));
if(p!=c.end())
{
if(p->se=='Q'||p->se=='B')flag=true;
}
//
p=d.lower_bound(mp(n,'B'));
if(p!=d.begin())
{
p--;
if(p->se=='Q'||p->se=='B')flag=true;
p++;
}
p=d.upper_bound(mp(n,'B'));
if(p!=d.end())
{
if(p->se=='Q'||p->se=='B')flag=true;
}
//
puts(flag?"YES":"NO");
//system("Pause");
return ;
}
Anton and Chess的更多相关文章
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
		
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...
 - 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 ...
 - 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 ...
 - 【29.89%】【codeforces 734D】Anton and Chess
		
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
 - Codeforces 734D. Anton and Chess(模拟)
		
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the pro ...
 - D. Anton and Chess 模拟题 + 读题
		
http://codeforces.com/contest/734/problem/D 一开始的时候看不懂题目,以为象是中国象棋那样走,然后看不懂样例. 原来是走对角线的,长知识了. 所以我们就知道, ...
 - Anton and Chess(模拟+思维)
		
http://codeforces.com/group/1EzrFFyOc0/contest/734/problem/D 题意:就是给你一个很大的棋盘,给你一个白棋的位置还有n个黑棋的位置,问你黑棋能 ...
 - 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 ...
 - Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black
		
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...
 
随机推荐
- 一行一行分析JQ源码学习笔记-05
			
创建字符串<li></li>$.function(){var str =} merge;用法 对外组数何必 对内部 还可以json合并var arr = ["a&qu ...
 - 苹果dock效果
			
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
 - Linux压缩与解压缩
			
.tar.gz 和 .tgz解压:tar zxvf FileName.tar.gz [-C Dir] 中括号中的内容可以省略.压缩:tar zcvf FileName.tar.gz DirName . ...
 - ubuntu 14.04 cagl
			
libboost-atomic1.-dev libboost-atomic1.-dev libboost-chrono1.-dev libboost-dev libboost-program-opti ...
 - golang的linux安装
			
1.wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz tar -zxvf go1.6.2.linux-amd6 ...
 - CentOS系统更换软件安装源aliyun的
			
CentOS系统更换软件安装源第一步:备份你的原镜像文件,以免出错后可以恢复. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS ...
 - mysql建表设置两个默认CURRENT_TIMESTAMP的技巧
			
转载:http://blog.163.com/user_zhaopeng/blog/static/166022708201252323942430/ 业务场景: 例如用户表,我们需要建一个字段是创 ...
 - HTTP基础知识
			
HTTP是计算机通过网络进行通信的规则,是一种无状态的协议,不建立持久的连接(客户端向服务器发送请求,web服务器返回响应,接着连接就被关闭了): 一个完整的HTTP请求连接,通常有下面7个步骤: 1 ...
 - 【洛谷P1352】没有上司的舞会
			
[洛谷P1352]没有上司的舞会 x舷售 锚」翅θ 但是 拙臃 蓄ⅶ榔 暄条熨卫 翘ヴ馇 表现无愧于雪月工作室的核心管理 爸惚扎掬 颇瓶 芟缆肝 貌痉了 洵┭笫装 嗝◇裴腋 褓劂埭 ...
 - cookie和session的区别(搜狐笔试考到的一个题目)
			
一.cookie机制和session机制的区别***************************************************************************** ...