zoukankan      html  css  js  c++  java
  • D. Anton and Chess Codeforces Round #379 (Div. 2)

    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.

    题目大意 , R B  Q 三种黑色棋子,R只能攻击同行同列,B只能攻击对角线上的棋子,C能攻击对角线和同行同列

    问黑色能否将白色将军,(如果满足要求,但在攻击的路线中有其他棋子,就不行

    思路 ,先将黑色棋子到白色棋子的距离排序**(核心),然后我是分成 8个区域一点点判断,就好了

     1 #include <algorithm>
     2 #include <stack>
     3 #include <istream>
     4 #include <stdio.h>
     5 #include <map>
     6 #include <math.h>
     7 #include <vector>
     8 #include <iostream>
     9 #include <queue>
    10 #include <string.h>
    11 #include <set>
    12 #include <cstdio>
    13 #define FR(i,n) for(int i=0;i<n;i++)
    14 #define MAX 2005
    15 #define mkp pair <int,int>
    16 using namespace std;
    17 #include <bits/stdc++.h>
    18 const int maxn = 5e6 + 40;
    19 typedef long long ll;
    20 const int  inf = 0x3fffff;
    21 void read(ll &x) {
    22     char ch; bool flag = 0;
    23     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
    24     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
    25     x *= 1 - 2 * flag;
    26 }
    27 int vis[105];
    28 struct inof{
    29     int flag;
    30     ll x,y;
    31     ll res;
    32 }p[maxn];
    33 bool cmp(inof a,inof b)
    34 {
    35     return a.res<b.res;
    36 }
    37 int getdir(ll x,ll y,ll z,ll m)
    38 {
    39     if(x==z&&y>m)return 0;
    40     if(x==z&&y<m)return 1;
    41     if(y==m&&x>z)return 2;
    42     if(y==m&&x<z)return 3; /// shang xia zuo you
    43 
    44     if(abs((m-y)/(z-x))!=1||(m-y)%(z-x))return -1;///这里wa了几发...
    45     if(x<z&&y<m)return 4;
    46     if(x<z&&y>m)return 5;
    47     if(x>z&&y<m)return 6;
    48     if(x>z&&y>m)return 7;
    49 }
    50 int main() {
    51     ll n;
    52     read(n);
    53     ll xx,yy;
    54     memset(vis,0,sizeof(vis));
    55     read(xx),read(yy);
    56     for(int i=0;i<n;i++){
    57        char c;
    58        scanf("%c",&c);
    59        if(c=='R')p[i].flag=0;/// 同行同列
    60        else if(c=='B')p[i].flag=1;/// 对角线
    61        else if(c=='Q')p[i].flag=2;/// 对角线同行同列
    62        read(p[i].x),read(p[i].y);
    63        p[i].res=abs(p[i].x-xx)+abs(p[i].y-yy);
    64     }
    65     sort(p,p+n,cmp);
    66     for(int i=0;i<n;i++){
    67         int flag = getdir(p[i].x,p[i].y,xx,yy);
    68         if(flag==-1)continue;
    69         if(vis[flag])continue;
    70         if(flag<=3&&(p[i].flag==0||p[i].flag==2)){return 0*printf("YES");}
    71         if(flag>3&&(p[i].flag==1||p[i].flag==2)){return 0*printf("YES");}
    72         vis[flag]=1;
    73     }
    74     puts("NO");
    75     return 0;
    76 }
  • 相关阅读:
    绑定class -vue
    二叉树按层打印,并且按层换行的方法
    curl相关知识
    python创建简单的http服务器
    有关rides数据库的想法
    java模拟实现有序表操作
    php静态方法
    php关闭浏览器不终止运行
    php读取图片以二进制输出
    借用face++人脸识别,来识别年龄
  • 原文地址:https://www.cnblogs.com/DreamKill/p/9452651.html
Copyright © 2011-2022 走看看