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 ...
随机推荐
- 转-CSS优先级(权重)解析
1.多个选择器可能会选择同一个元素,有3个规则,从上到下重要性降低: !important的用户样式 !important的作者样式 作者样式 用户样式 浏览器定义的样式 2. CSS规范为不同类型的 ...
- POJ 2505 A multiplication game(找规律博弈/贪心)
题目链接 #include<iostream> #include<cstdio> using namespace std; typedef long long ll; int ...
- MongoDB数据模型(二)
原文地址 接上一篇 四.模型树结构 父引用的模型树结构 这个数据模型描述了一个树形结构,在子节点中存储父节点的引用. 模式 父引用模式存储每个树节点到文档中,除了树节点外,文档还存储了父节点的id. ...
- UESTC 1272 Final Pan's prime numbers(乱搞)
题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...
- js刷新页面不回到顶部
今天遇到刷新页面不回到顶部的需求 window.location.reload();方法已经解决了问题,但是ie8不支持,后来采用的是锚点这个方法 window.location = '/plan/g ...
- Arch下载官方镜像列表Official mirrors
Official mirrors The official Arch Linux mirror list is available from the pacman-mirrorlist package ...
- 洛谷-小鱼会有危险吗-BOSS战-入门综合练习2
题目描述 Description 有一次,小鱼要从A处沿直线往右边游,小鱼第一秒可以游7米,从第二秒开始每秒游的距离只有前一秒的98%.有个极其邪恶的猎人在距离A处右边s米的地方,安装了一个隐蔽的探测 ...
- 洛谷-烤鸡-BOSS战-入门综合练习1
题目背景 Background 猪猪hanke得到了一只鸡 题目描述 Description 猪猪Hanke特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke吃鸡很特别,为什么特别呢?因为他有10 ...
- eclipse设置java虚拟机内存大小
设置java虚拟机大小可以让eclipse启动运行更快...... 在eclipse中点击window--preferences--java--Installed JREs. 然后看右边的框,鼠标点击 ...
- 使用observable数组(Working with observable arrays)
observable数组(observable arrays) 如果你要探测和响应一个对象的变化,你应该用observables.如果你需要探测和响应一个集合对象的变化,你应该用observableA ...