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

链接:http://codeforces.com/contest/734/problem/D

题意:给定一个白棋的位置,然后给n个黑棋(只有象,车和皇后),象走斜率为+-1的方向,车走十字,皇后走米字。判断是否有黑棋能一步吃掉白棋。

分析:白棋被吃掉只能被8个方向上最近的那个点吃,处理出n个黑棋中距离白棋最近的且在那8个方向上的是什么类型的棋子就行了。

代码:

#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const db eps=1e-5;
const int N=5e5+10;
const int M=4e6+10;
const ll MOD=1000000007;
const int mod=1000000007;
const int MAX=2000000010;
const double pi=acos(-1.0);
char s[2];
int w[10],dis[10];
int get(char ch) {
    if (ch=='B') return 1;
    if (ch=='R') return 2;
    return 3;
}
int main()
{
    int i,n,bo=0,x,y,xx,yy;
    scanf("%d", &n);
    scanf("%d%d", &x, &y);
    memset(w,0,sizeof(w));
    for (i=1;i<=4;i++) dis[i]=MAX;
    for (i=5;i<=8;i++) dis[i]=-MAX;
    for (i=1;i<=n;i++) {
        scanf("%s%d%d", s, &xx, &yy);
        if (xx!=x&&yy!=y&&abs(xx-x)!=abs(yy-y)) continue ;
        if (xx==x&&yy==y) bo=1;

        if (xx==x) {
            if (yy>y&&yy<dis[1]) dis[1]=yy,w[1]=get(s[0]);
            if (yy<y&&yy>dis[5]) dis[5]=yy,w[5]=get(s[0]);
        }
        if (yy==y) {
            if (xx>x&&xx<dis[3]) dis[3]=xx,w[3]=get(s[0]);
            if (xx<x&&xx>dis[7]) dis[7]=xx,w[7]=get(s[0]);
        }
        if (x-xx==y-yy) {
            if (xx>x&&xx<dis[2]) dis[2]=xx,w[2]=get(s[0]);
            if (xx<x&&xx>dis[6]) dis[6]=xx,w[6]=get(s[0]);
        }
        if (x-xx==yy-y) {
            if (xx>x&&xx<dis[4]) dis[4]=xx,w[4]=get(s[0]);
            if (xx<x&&xx>dis[8]) dis[8]=xx,w[8]=get(s[0]);
        }
    }
    for (i=1;i<=8;i++)
    if (w[i]) {
        if ((i==2||i==4||i==6||i==8)&&(w[i]==1||w[i]==3)) bo=1;
        if ((i==1||i==3||i==5||i==7)&&(w[i]==2||w[i]==3)) bo=1;
    }
    if (bo) printf("YES\n");
    else printf("NO\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值