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

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;
}
时间: 2024-10-11 06:55:02

Codeforces Round #379 (Div. 2) D. Anton and Chess(模拟)的相关文章

Codeforces Round #379 (Div. 2) C. Anton and Making Potions(二分)

Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare npotions. Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two typ

Codeforces Round #379 (Div. 2) E. Anton and Tree

题意:给你一棵树, 每个点要么是黑色要么是白色, 有一种操作是将同一个颜色的连通块变成相反的颜色,问你最少变换几次, 整颗树变成一种颜色. 思路: 缩点, 加求树的直径, 答案为树的直径除二向上取整. 1 #include<bits/stdc++.h> 2 #define LL long long 3 #define mk make_pair 4 using namespace std; 5 6 const int N = 5e5 + 7; 7 const int inf = 0x3f3f3f

Codeforces Round #253 (Div. 2) A. Anton and Letters

题目很简单,只需要注意带空格的输入用getline即可 #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> using namespace std; int main(){ string str; getline(cin,str); set<char> a; for(int i= 1 ; i < s

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟 枚举

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟  枚举 题意 一个红绿灯 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道让你判断,汽车是否有可能撞到行人 注意 当前车道的左转有可能撞到别的车道的行人的 题解 一大堆特判 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring&g

Codeforces Round #379 (Div. 2) Analyses By Team:Red &amp; Black

A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同

Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心

B. Anton and Lines The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessar

Codeforces Round #379 (Div. 2) 总结分享

前言 初入acm的新手,打算在cf混.这几天没有比赛,就做了个最新的Virtual participation.虽然说div2比较简单,但还是被虐得体无完肤...Orz.两个小时,共6道题.最后只AC了AB两道,花了20分钟,剩下的100分钟也不知道哪去了(逃 A.B两道水题没什么说的.那我们从C题开始吧: C. Anton and Making Potions 题意: 制作n瓶药水,初始时每制作一瓶花费x秒,有两类法术,第一类(包含m个法术)使制作每瓶药的时间由x变为a[i] (a[i] <

Codeforces Round #379 (Div. 2) 解题报告

题目地址 本次CF是在今天早上深夜进行,上午有课就没有直接参加.今天早上上课坐到后排参加了virtual participation.这次CF前面的题目都非常的水,不到10分钟就轻松过了前两题,比较郁闷的是之后一直卡在C,开始是脑残的没有用二分TLE,后来又是因为一个常数打错而一直WA--于是模拟赛就只过了2道题(太弱了orz).时间到了后很快发现了脑残错误,终于A了C题.下午上完课回到宿舍看D题才发现D题水的不行,很快就A了.不过E和F就比较超出我现在知识范围了,暂时就先放下.第一次参加vir

Codeforces Round #288 (Div. 2) B. Anton and currency you all know

B. Anton and currency you all know time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that