Codeforces Round菗379(Div.2)D.Anton and Chess水題

3325 ワード

D.Anton and Chess
テーマ接続:
http://codeforces.com/contest/734/problem/D
Description
Anton likes to Playchess.Also,he likes to do programming.That is why he decided to write the program that plass chess.However,he finds the game on 8 to 8 board too simple,he es an finite stead.
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.
Consinder that an infinite chess board contains one white king and the number of black pieces.The e e e are only rook s,bishop and queens,as the other pieces are e e not supported yet.The white king king king the is id id id id the blacemith the
Help Anton and write the program that for the given position determines wher the white king is in check.
Remander、on how dochecs pieces move:
Bishop moves any number of celsdiagonally、but it can't"leap"over the occued cels. Rook moves any number of celshorizontallyor verticaly、but t italsocan't"leap"over the over the over the propropropropropropropopopopopopopopopopopos.s s.orororororororororormmmmmmmmbebebebebel l l l l l l l l l l l l l l.orororororororororororormomomomomomomomomomomomomomomomomomomomomomomomomomocan't"leap"
Input
The first line of the input contains a single integer n(1̵≦n̵≦?500?000)-the number of black piecs.
The second line contains two integers x 0 and y 0(̵-̵109̵≦?x 0,?0̵≦?109)—coordinans of the white king.
The n follw nオンラインs、each of them contains a charactr and two integers xi and yi(?-?109?109?≤?xi、???109)—type of the i-th piece piecandandinininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininanteed thatのtwo piece s occupy the same position.
Output
The only line of the output shout contains「YES」if the white king is in check and「NO」(without quot tes)otherswise.
Sample Input
2 4 2 R 1 B 1 5
Sample Output
YES
ベント
題意
つの無限大の平面、あなたに1つのKingの位置をあげて、更にその他の駒の位置をあげて、あなたにこのKingは人の将軍にあるかどうかを聞きます。
クイズ:
キングの8方向の一番近い駒だけを考えて記録すればいいです。
コード
#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");
}