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.

题意:就是给你一个很大的棋盘,给你一个白棋的位置还有n个黑棋的位置,问你黑棋能否一步就吃掉白棋

给你如下规则

1.‘B'只能对角线移动,而且不能越过其他黑棋。

2.’R'只能上下左右移动,而且不能越过其他黑棋。

3.‘Q’既能对角线移动又能左右移动,但是不能越过其他黑棋。

其实也就是个模拟题,但也有一些技巧,只要考虑白棋的正上方,正下方,正左方,正右方距离白棋最小的是否为‘R'or’Q'。

斜右上角,斜右下角,斜左下角,斜左上角距离白棋最小的是否为‘B'or’Q'。即可。还有就是要注意一下小细节。

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
const int M = 5e5 + 10;
struct TnT {
char cp[2];
int x , y;
}s[M];
int main()
{
int t;
scanf("%d" , &t);
int x0 , y0;
scanf("%d%d" , &x0 , &y0);
int flag = 0;
for(int i = 0 ; i < t ; i++) {
scanf("%s %d %d" , s[i].cp , &s[i].x , &s[i].y);
if(s[i].x == x0 && s[i].y == y0)
flag = 1;
//cout << s[i].cp << ' ' << s[i].x << ' ' << s[i].y << endl;
}
for(int i = 0 ; i < 8 ; i++) {
int temp = 0;
int MIN = 2e9 + 10;
if(i == 0) {
for(int j = 0 ; j < t ; j++) {
if(s[j].x == x0 && s[j].y > y0) {
int gg = abs(s[j].y - y0);
if(MIN > gg) {
temp = j;
MIN = gg;
}
}
}
if((MIN != 2e9 + 10) && (s[temp].cp[0] == 'R' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
if(i == 1) {
for(int j = 0 ; j < t ; j++) {
if(s[j].x == x0 && s[j].y < y0) {
int gg = abs(s[j].y - y0);
if(MIN > gg) {
temp = j;
MIN = gg;
}
}
}
if((MIN != 2e9 + 10) && (s[temp].cp[0] == 'R' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
if(i == 2) {
for(int j = 0 ; j < t ; j++) {
if(s[j].y == y0 && s[j].x > x0) {
int gg = abs(s[j].x - x0);
if(MIN > gg) {
temp = j;
MIN = gg;
}
}
}
if((MIN != 2e9 + 10) && (s[temp].cp[0] == 'R' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
if(i == 3) {
for(int j = 0 ; j < t ; j++) {
if(s[j].y == y0 && s[j].x < x0) {
int gg = abs(s[j].x - x0);
if(MIN > gg) {
temp = j;
MIN = gg;
}
}
}
if((MIN != 2e9 + 10) && (s[temp].cp[0] == 'R' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
ll MIN2 = 9e18;
if(i == 4) {
for(int j = 0 ; j < t ; j++) {
if((s[j].y - y0) == -1 * (s[j].x - x0) && s[j].y > y0 && s[j].x < x0) {
int x1 = abs(s[j].x - x0);
int y1 = abs(s[j].y - y0);
ll gg = (ll)x1 * x1 + (ll)y1 * y1;
if(MIN2 > gg) {
temp = j;
MIN2 = gg;
} }
}
if((MIN2 != 9e18) && (s[temp].cp[0] == 'B' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
if(i == 5) {
for(int j = 0 ; j < t ; j++) {
if((s[j].y - y0) == -1 * (s[j].x - x0) && s[j].y < y0 && s[j].x > x0) {
int x1 = abs(s[j].x - x0);
int y1 = abs(s[j].y - y0);
ll gg = (ll)x1 * x1 + (ll)y1 * y1;
if(MIN2 > gg) {
temp = j;
MIN2 = gg;
} }
}
if((MIN2 != 9e18) && (s[temp].cp[0] == 'B' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
if(i == 6) {
for(int j = 0 ; j < t ; j++) {
if((s[j].y - y0) == (s[j].x - x0) && s[j].y < y0 && s[j].x < x0) {
int x1 = abs(s[j].x - x0);
int y1 = abs(s[j].y - y0);
ll gg = (ll)x1 * x1 + (ll)y1 * y1;
if(MIN2 > gg) {
temp = j;
MIN2 = gg;
} }
}
if((MIN2 != 9e18) && (s[temp].cp[0] == 'B' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
if(i == 7) {
for(int j = 0 ; j < t ; j++) {
if((s[j].y - y0) == (s[j].x - x0) && s[j].y > y0 && s[j].x > x0) {
int x1 = abs(s[j].x - x0);
int y1 = abs(s[j].y - y0);
ll gg = (ll)x1 * x1 + (ll)y1 * y1;
if(MIN2 > gg) {
temp = j;
MIN2 = gg;
} }
}
if((MIN2 != 9e18) && (s[temp].cp[0] == 'B' || s[temp].cp[0] == 'Q')) {
flag = 1;
}
if(flag == 1)
break;
else
continue;
}
if(flag == 1)
break;
}
if(flag == 0)
printf("NO\n");
else
printf("YES\n");
return 0;
}

Codeforces 734D. 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 test4 secondsmem ...

  2. D. Anton and Chess 模拟题 + 读题

    http://codeforces.com/contest/734/problem/D 一开始的时候看不懂题目,以为象是中国象棋那样走,然后看不懂样例. 原来是走对角线的,长知识了. 所以我们就知道, ...

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

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

  5. Anton and Chess

    Anton and Chess time limit per test 4 seconds memory limit per test 256 megabytes input standard inp ...

  6. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  7. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. Anton and Chess(模拟+思维)

    http://codeforces.com/group/1EzrFFyOc0/contest/734/problem/D 题意:就是给你一个很大的棋盘,给你一个白棋的位置还有n个黑棋的位置,问你黑棋能 ...

  9. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

随机推荐

  1. JAVA并发编程之倒计数器CountDownLatch

    CountDownLatch 的使用场景:在主线程中开启多线程去并行执行任务,并且主线程需要等待所有子线程执行完毕后汇总返回结果. 我把源码中的英文注释全部删除,写上自己的注释.就剩下 70 行不到的 ...

  2. 用python实现九九乘法表输出-两种方法

    2019-08-05 思考过程:九九乘法表需要两层循环,暂且称之为内循环和外循环,因此需要写双层循环来实现. 循环有for和while两种方式. for循环的实现 for i in range(1,1 ...

  3. Hadoop 系列(四)—— Hadoop 开发环境搭建

    一.前置条件 Hadoop 的运行依赖 JDK,需要预先安装,安装步骤见: Linux 下 JDK 的安装 二.配置免密登录 Hadoop 组件之间需要基于 SSH 进行通讯. 2.1 配置映射 配置 ...

  4. 『开发技术』GPU训练加速原理(附KerasGPU训练技巧)

    0.深入理解GPU训练加速原理 我们都知道用GPU可以加速神经神经网络训练(相较于CPU),具体的速度对比可以参看我之前写的速度对比博文: [深度应用]·主流深度学习硬件速度对比(CPU,GPU,TP ...

  5. 逛公园「NOIP2017」最短路+DP

    大家好我叫蒟蒻,这是我的第一篇信竞题解blog [题目描述] 策策同学特别喜欢逛公园. 公园可以看成一张 \(N\) 个点 \(M\) 条边构成的有向图,且没有自环和重边.其中 \(1\) 号点是公园 ...

  6. 一个web前端开发者的日常唠叨

    时间飞逝,距离上一次更新博客已经过去了三个月,上一篇博客的发布时间停留在了4月4日. 近来三个月没有更新博客,深感抱歉和愧疚.停更博客就意味着学习的越来越少,作为一个普通的前端开发者来说这是万万不可取 ...

  7. 浅谈 JavaScript 垃圾回收机制

    github 获取更多资源 https://github.com/ChenMingK/WebKnowledges-Notes 在线阅读:https://www.kancloud.cn/chenmk/w ...

  8. Git原理入门简析

    为了获得更好的阅读体验,建议访问原地址:传送门 前言: 之前听过公司大佬分享过 Git 原理之后就想来自己总结一下,最近一忙起来就拖得久了,本来想塞更多的干货,但是不喜欢拖太久,所以先出一版足够入门的 ...

  9. 使用Cmake编译CEF时遇到Error in configuration process,project file may be invalid的解决办法

    今天在用Cmake编译cef框架时,弹出了错误,如图: 可以排查一下几种原因: 1.在64位计算机编译32位程序 可以更换编译环境,或者下载64位版本来解决这个问题. 2.选择的Visual Stud ...

  10. 设计一个完美的http缓存策略

    1.前言 作为一个前端,了解http缓存是非常必要,它不仅是面试的必要环节,也更是实战开发中必不可少需要了解的知识点,本文作者将从缓存的概念讲到如何在业务中设计一个合理的缓存架构,带你一步一步解开ht ...