CodeForces 734D Anton and Chess 【模拟】

题目:点击打开链接

题意:给定一个白棋坐标,给出n个黑色的棋子的坐标,表示象,车,女王的中的一个,棋子不能越过另一个棋子,问是否白棋能被吃掉

分析:以白棋为中心,分散中八条横竖斜的射线,储存与最近的黑棋的距离,再遍历一遍黑棋,看是否满足黑棋距离等于该射线的最近距离且能吃掉白棋

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <map>
#define sqr(x) ((x)*(x))
#define PR pair<int,int>
#define MP make_pair
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
const ll INF = (1ULL<<63)-1;
const int inf=0x3f3f3f3f;
const int M=100010;
const int N=500010;
const ll MOD=1000000007;
const double eps=1e-3;
const double pi=acos(-1.0);
using namespace std;
struct node{char s[3];int x,y;}p[N];
ll n,sx,sy,x,y,a[8];
char s[3];
ll dis(ll x,ll y) {return abs(x-sx)+abs(y-sy);}
bool judge(ll x,ll y){return abs(x-sx)==abs(y-sy);}
int main()
{
    int i,ok=0;
    for(i=0;i<8;i++)a[i]=INF;
    scanf("%I64d%I64d%I64d",&n,&sx,&sy);
    for(i=0;i<n;i++)
    {
        scanf("%s%I64d%I64d",s,&x,&y);
        strcpy(p[i].s,s);p[i].x=x,p[i].y=y;
        ll d=dis(x,y);
        if(x<sx&&y==sy) a[0]=min(a[0],d);
        if(x==sx&&y>sy) a[2]=min(a[2],d);
        if(x>sx&&y==sy) a[4]=min(a[4],d);
        if(x==sx&&y<sy) a[6]=min(a[6],d);
        if(judge(x,y))
        {
            if(x<sx&&y>sy) a[1]=min(a[1],d);
            if(x>sx&&y>sy) a[3]=min(a[3],d);
            if(x>sx&&y<sy) a[5]=min(a[5],d);
            if(x<sx&&y<sy) a[7]=min(a[7],d);
        }
    }
    for(i=0;i<n;i++)
    {
        strcpy(s,p[i].s);x=p[i].x,y=p[i].y;
        ll d=dis(x,y);
        if(s[0]=='R'||s[0]=='Q')
        {
            if(x<sx&&y==sy&&a[0]>=d) ok=1;
            if(x==sx&&y>sy&&a[2]>=d) ok=1;
            if(x>sx&&y==sy&&a[4]>=d) ok=1;
            if(x==sx&&y<sy&&a[6]>=d) ok=1;
        }
        if(s[0]=='B'||s[0]=='Q')
        {
            if(judge(x,y))
            {
                if(x<sx&&y>sy&&a[1]==d) ok=1;
                if(x>sx&&y>sy&&a[3]==d) ok=1;
                if(x>sx&&y<sy&&a[5]==d) ok=1;
                if(x<sx&&y<sy&&a[7]==d) ok=1;
            }
        }
    }
    if(ok) puts("YES");else puts("NO");
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值