Codeforces Round #379 (Div. 2) -- D. Anton and Chess (if else 的水题)

来源:互联网 发布:深圳华夏软件学校招生 编辑:程序博客网 时间:2024/04/30 11:43

大体题意:

给你国际象棋一种残局,问白方是否已经输掉!  (下一步该黑方走)  黑方的棋有三种  (只能横着走 和 只能斜着走 和 既能横着走又能斜着走! = =  没玩过国际象棋 (勿喷!))

思路:

因为这个棋盘太大了,最大20亿×20亿 肯定不能乱扫!

其实思路很简单:

直接统计出 白方棋子 八个方向上  最近的黑方棋子即可!  然后  讨论这八个方向是否有棋,有棋的话能否被吃掉!

参考下if else 的代码把 = =:

#include <bits/stdc++.h>#define ps push_back#define fi first#define se second#define mr make_pairusing namespace std;typedef long long ll;typedef unsigned long long LLU;const int inf = (0x3f3f3f3f) << 1;const double eps = 1e-10;const double pi = acos(-1.0);char s[20];int a[8];char b[8];int main(){    int n;    scanf("%d",&n);    int x0,y0;    scanf("%d %d",&x0,&y0);    a[0] = -inf,a[1] = inf,a[2] = -inf,a[3] = inf;    a[4] = -inf,a[5] = inf,a[6] = inf,a[7] = -inf;    memset(b,0,sizeof b);    for (int i = 0; i < n; ++i){        int r,c;        scanf("%s %d %d", s, &r, &c);        if (r == x0){ //  yes            if (c < y0){                if (c > a[0]){                    a[0] = c;                    b[0] = s[0];                }            }            else {                if (c < a[1]){                    a[1] = c;                    b[1] = s[0];                }            }        }        else if (c == y0){            if (r < x0){                if (r > a[2]){                    a[2] = r;                    b[2] = s[0];                }            }            else {                if (r < a[3]){                    a[3] = r;                    b[3] = s[0];                }            }        }        else if (r - c == x0 - y0){            if (r + c < x0 + y0){                if (r + c > a[4]){                    a[4] = r + c;                    b[4] = s[0];                }            }            else {                if (r+c < a[5]){                    a[5] = r+c;                    b[5] = s[0];                }            }        }        else if (r + c == x0 + y0){            if (r-c > x0-y0){                if (r-c < a[6]){                    a[6] = r-c;                    b[6] = s[0];                }            }            else {                if (r-c > a[7]){                    a[7] = r-c;                    b[7] = s[0];                }            }        }    }    bool ok = 0;    for (int i = 0; i < 4; ++i){        if (b[i] == 'R' || b[i] == 'Q') ok = 1;    }    for (int i = 4; i < 8; ++i){        if (b[i] == 'B' || b[i] == 'Q') ok = 1;    }//    printf("%c\n",b[7]);    if (ok)puts("YES");    else puts("NO");    return 0;}/**3-1000000000 -1000000000B 1000000000 -1000000000B -1000000000 1000000000B 1000000000 10000000003-1 -1B 1 -1B -1 1B 1 1**/


D. Anton and Chess
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
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".
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.

Examples
input
24 2R 1 1B 1 5
output
YES
input
24 2R 3 3B 1 5
output
NO
Note

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

0 0
原创粉丝点击