Anton and Chess CodeForces - 734D 模拟

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.

Example
Input
2
4 2
R 1 1
B 1 5
Output
YES
Input
2
4 2
R 3 3
B 1 5
Output
NO

判断最后是否被将军,注意前面的棋子虽然可能将军到,但是后面的棋子可能会挡住。储存王的八个方向上的最近的棋子,每当有棋子放到该方向上而且离王更近则更新棋子,最后检验一遍

#include <iostream>
#include <stdio.h>
using namespace std;
long long a,b;

int main()
{
    long long n,x,y,flag;
    char c;
    scanf("%I64d\n%I64d %I64d",&n,&a,&b);
    flag=0;
    long long e=10000000000;
    long long s1[10]={0,-e,-e,-e,a,a,e,e,e};
    long long s2[10]={0,e,b,e,-e,e,-e,b,-e};
    char sc[10]={0,0,0,0,0,0,0,0,0,0};
    for(int i=0;i<n;i++){
        getchar();
        scanf("%c %I64d %I64d",&c,&x,&y);

        if(x==a){
            if(y>b&&y<s2[5]){
                s2[5]=y;
                sc[5]=c;
            }
            if(y<b&&y>s2[4]){
                s2[4]=y;
                sc[4]=c;
            }
        }else if(y==b){
            if(x>a&&x<s1[7]){
                s1[7]=x;
                sc[7]=c;
            }
            if(x<a&&x>s1[2]){
                s1[2]=x;
                sc[2]=c;
            }
        }else if((b+(x-a))==y){
            if(y>b&&y<s2[3]){
                s2[3]=y;
                s1[3]=x;
                sc[3]=c;
            }
            if(y<b&&y>s2[6]){
                s2[6]=y;
                s1[6]=x;
                sc[6]=c;
            }
        }else if((b-(x-a))==y){
            if(y<b&&y>s2[8]){
                s2[8]=y;
                s1[8]=x;
                sc[8]=c;
            }
            if(y>b&&y<s2[1]){
                s2[1]=y;
                s1[1]=x;
                sc[1]=c;
            }
        }
    }
    if(sc[2]=='R'||sc[4]=='R'||sc[5]=='R'||sc[7]=='R'||sc[1]=='B'||sc[3]=='B'||sc[6]=='B'||sc[8]=='B'){
        flag=1;
    }
    for(int i=1;i<=8;i++){
        if(sc[i]=='Q'){
            flag=1;
        }
    }
    if(flag){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}
基于Swin Transformer与ASPP模块的图像分类系统设计与实现 本文介绍了一种结合Swin Transformer与空洞空间金字塔池化(ASPP)模块的高效图像分类系统。该系统通过融合Transformer的全局建模能力和ASPP的多尺度特征提取优势,显著提升了模型在复杂场景下的分类性能。 模型架构创新 系统核心采用Swin Transformer作为骨干网络,其层次化窗口注意力机制能高效捕获长距离依赖关系。在特征提取阶段,创新性地引入ASPP模块,通过并行空洞卷积(膨胀率6/12/18)和全局平均池化分支,实现多尺度上下文信息融合。ASPP输出经1x1卷积降维后与原始特征拼接,有效增强了模型对物体尺寸变化的鲁棒性。 训练优化策略 训练流程采用Adam优化器(学习率0.0001)和交叉熵损失函数,支持多GPU并行训练。系统实现了完整的评估指标体系,包括准确率、精确率、召回率、特异度和F1分数等6项指标,并通过动态曲线可视化模块实时监控训练过程。采用早停机制保存最佳模型,验证集准确率提升可达3.2%。 工程实现亮点 1. 模块化设计:分离数据加载、模型构建和训练流程,支持快速迭代 2. 自动化评估:每轮训练自动生成指标报告和可视化曲线 3. 设备自适应:智能检测CUDA可用性,无缝切换训练设备 4. 中文支持:优化可视化界面的中文显示与负号渲染 实验表明,该系统在224×224分辨率图像分类任务中,仅需2个epoch即可达到92%以上的验证准确率。ASPP模块的引入使小目标识别准确率提升15%,特别适用于医疗影像等需要细粒度分类的场景。未来可通过轻量化改造进一步优化推理速度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值