Xiangqi UVA - 1589

题目链接:Xiangqi UVA - 1589
题目:考虑一个象棋残局,其中红方有 n2<=n<=7 n ( 2 <= n <= 7 ) 个棋子,黑方只有一个将,红方除了有一个帅(G)之外还有3种可能的棋子:车(R),马(H),炮(C),并且需要考虑“bie马腿”与将和帅不能照面的规则。
输入所有棋子所在位置,保证局面合法并且红方已经将军。你的任务是判断红方是否已经将黑方将死。

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<iomanip>
#define ll long long

using namespace std;

int n,x,y,a,b;
int xq[11][10];
struct qz{
    char z;
    int x,y;
}s[10];

bool GG(int a1, int b1) {
    if(b1 == b) {
        for(int i = a - 1; i > a1; i--) if(xq[i][b] != 0) return false;
        return true;
    }
    return false;
}

bool RG(int a1, int b1,int a2, int b2){
    if(a1 == a2) {
        int y1 = b1,y2 = b2;
        if(y1>y2) swap(y1,y2);
        for(int i = y1 + 1; i < y2; i++) if(xq[a1][i] != 0) return false;
        return true;
    }
    if(b1 == b2){
        int x1 = a1,x2 = a2;
        if(x1>x2) swap(x1,x2);
        for(int i = x1 + 1; i < x2; i++) if(xq[i][b1] != 0) return false;
        return true;
    }
    return false;
}

bool CG(int a1, int b1,int a2, int b2){
    if(a1 == a2) {
        int y1 = b1,y2 = b2;
        if(y1>y2) swap(y1,y2);
        for(int i = y1+1; i < y2; i++) if(xq[a1][i] != 0) return true;
        return false;
    }
    if(b1 == b2){
        int x1 = a1,x2 = a2;
        if(x1>x2) swap(x1,x2);
        for(int i = x1+1; i < x2; i++) if(xq[i][b1] != 0) return true;
        return false;
    }
    return false;
}

bool HG(int a1, int b1,int a2, int b2){
    if((a1 == (a2 - 2)&&b1 == (b2 - 1))||((a1 == (a2 - 2)&&b1 == (b2 + 1)))) {
        if(xq[a2 - 1][b2] == 0) return true;
    }
    if((a1 == (a2 + 2)&&b1 == (b2 - 1))||((a1 == (a2 + 2)&&b1 == (b2 + 1)))) {
        if(xq[a2 + 1][b2] == 0) return true;
    }
    if((a1 == (a2 - 1)&&b1 == (b2 - 2))||((a1 == (a2 + 1)&&b1 == (b2 - 2)))) {
        if(xq[a2][b2 - 1] == 0) return true;
    }
    if((a1 == (a2 - 1)&&b1 == (b2 + 2))||((a1 == (a2 + 1)&&b1 == (b2 + 2)))) {
        if(xq[a2][b2 + 1] == 0) return true;
    }
    return false;
}
bool G(int a1,int b1) {
    if(a1<1||a1>3||b1<4||b1>6) return true;
    for(int i = 0; i < n; i++){
        if(s[i].x == a1&s[i].y == b1) continue;
        if(s[i].z == 'G'){
            if(GG(a1,b1)) return true;
        } else if(s[i].z == 'R'){
            if(RG(a1, b1, s[i].x, s[i].y)) return true;
        } else if(s[i].z == 'H'){
            if(HG(a1, b1, s[i].x, s[i].y)) return true;
        } else if(s[i].z == 'C') {
            if(CG(a1, b1, s[i].x, s[i].y)) return true;
        }
    }
    return false;
}


int main(){

    while(1) {
        scanf("%d%d%d", &n, &x, &y);
        if(n == 0) break;
        memset(xq, 0, sizeof(xq));
        for(int i = 0; i < n; i++) {
            getchar();
            scanf("%c%d%d", &s[i].z, &s[i].x, &s[i].y);
            xq[(s[i].x)][(s[i].y)] = s[i].z;
            if(s[i].z == 'G') { a = s[i].x; b = s[i].y; }
        }
        //cout << G(x,y-1)<<G(x,y+1)<<G(x-1,y)<<G(x+1,y) << endl;
        if(G(x,y-1)&&G(x,y+1)&&G(x-1,y)&&G(x+1,y)) puts("YES");
        else puts("NO");
    }
    return 0;
}
阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Flutter象棋是一款使用Flutter框架开发的象棋游戏。Flutter是一种跨平台的移动应用程序开发框架,它允许开发者使用一套代码同时构建iOS和Android应用。在Flutter象棋游戏的开发过程中,开发者可以参考国际象棋的软件理论,并使用通用引擎协议(UCCI)进行象棋界面和象棋引擎之间的通讯。该游戏的开发者的专栏中详细介绍了开发过程中遇到的问题以及解决问题的方式,不仅限于Flutter或Dart语言,而是以实用为导向。通过这个游戏的开发,你可以获得除了语言或框架之外的经验和知识。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [中国象棋通用引擎协议 UCCI](https://blog.csdn.net/tosmart/article/details/108728853)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [实战 Flutter 象棋从零到上架](https://blog.csdn.net/valada/article/details/105827625)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Whowell

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值