codeforces734D

来源:互联网 发布:网络综艺为什么这么火 编辑:程序博客网 时间:2024/06/08 14:52

题目链接: codeforces734D

题意: 

已知一共有N个黑色的棋子,对应白色的棋子的位子也是已知的。

已知黑色棋子一共有三种:

B:只能攻击对角线上的敌人。

R:只能攻击其同行同列的敌人。

Q:能够攻击对角线和同行同列上的敌人。

每个棋子都不能跨越另外一个棋子去吃其他棋子。

#include<bits/stdc++.h>using namespace std;struct chess{    int x, y;    char type;    bool friend operator < (chess a, chess b)    {        return a.x == b.x ? a.y < b.y : a.x <b.x;    }}c[500005];vector<chess>G[4];int n,sx,sy;char cc;int px, py;int main(){    scanf("%d", &n);    scanf("%d%d", &sx, &sy);   // getchar();    for(int i = 1; i <= n; i++)    {        scanf(" %c %d %d", &c[i].type, &c[i].x, &c[i].y);        //chess{px , py ,c};        if(c[i].x == sx)            G[0].push_back(c[i]);        else if(c[i].y == sy)            G[1].push_back(c[i]);        else if(c[i].x-c[i].y == sx-sy)            G[2].push_back(c[i]);        else if(c[i].x+c[i].y == sx+sy)            G[3].push_back(c[i]);    }    int now;    for(int i = 0; i < 4; i++)        sort(G[i].begin(), G[i].end());    for(int i = 0; i < 4; i++)    {        int point = upper_bound(G[i].begin(), G[i].end(), chess{sx,sy,1}) - G[i].begin();        //cout<<point<<endl;        int p = point;        if(i < 2)        {            if(p < G[i].size() && G[i][p].type != 'B')          {              printf("YES\n"); return 0;}            p -=1;            if(p >= 0 && G[i][p].type != 'B'){printf("YES\n");return 0;}        }        else        {             if(p < G[i].size() && G[i][p].type != 'R')            {printf("YES\n"); return 0;}             p -=1;            if(p >= 0 && G[i][p].type != 'R'){printf("YES\n"); return 0;}        }    }    printf("NO\n");    return 0;}

问是否白色棋子已经被将军了。

思路: 

只需要找到离king各个方向上的棋, 找到大于king的位置 - 1 就是小于 king位置的( >=0)(具体方法:vector, upper_bound)



原创粉丝点击