刘汝佳紫书 uva220 解题报告

这篇博客记录了作者在解决UVA220问题时的心路历程,面对与象棋相关的题目,作者采用了定义点的黑白状态及关联点的方法来覆盖棋子,并详细说明了解决过程中遇到的输出格式问题,如点之间空格、回合空行和黑白棋子数量的特定输出格式。虽然过程艰辛,但最终成功AC,作者对此感到非常激动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

没想到AC了好感动啊。。。

前面的那道象棋蜜汁WA把我搞的身心俱疲,又见到一个和棋有关的题就怂了啊

本来觉得会和象棋那题一样蜜汁WA的说,结果提交的时候看到presentation error整个心是紧了一下好吗!!简直是初恋的感觉啊!!

我的做法是把棋盘上的每个点都定义两个值来判断是否为黑子或者白子可落点,然后每个可落点都有一系列关联点,用于之后落子时将改点和关联点之间的棋子全部覆盖为同色。



结果这题输出及其坑爹。。。

输出注意:

1、打印有效点的时候每个点之间都有空格,但是最后一个点后面不能有

2、每个回合之间有空行(这个想必大家都会注意到)

3、输出黑白棋子各自剩余多少时,应该按照Black - xx White - yy这样的格式输出,就是要注意输出长度

自己没有仔细看题的习惯呢。。


下面是代码,那些用5000bytes就能解决的人好厉害啊。。。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct point{
    int r;
    int c;
};
struct unit{
    bool b_legal,w_legal;
    point correlation[1000];
    int c_n;
    int type;//1:black 2:white
};
unit bot[15][15];
void up(int type,int r,int c){
    int t=r-1;
    if(r-1>=1){
        r--;
        while(bot[r][c].type==type){
            r--;
        }
        if(t!=r){
            if(type==1){bot[r][c].w_legal=1;}else{bot[r][c].b_legal=1;}
            bot[r][c].correlation[bot[r][c].c_n].r=t+1;
            bot[r][c].correlation[bot[r][c].c_n].c=c;
            bot[r][c].c_n++;
        }
    }
}
void down(int type,int r,int c){
    int t=r+1;
    if(r+1<9){
        r++;
        while(bot[r][c].type==type){
            r++;
        }
        if(t!=r){
            if(type==1){bot[r][c].w_legal=1;}else{bot[r][c].b_legal=1;}
            bot[r][c].correlation[bot[r][c].c_n].r=t-1;
            bot[r][c].correlation[bot[r][c].c_n].c=c;
            bot[r][c].c_n++;
        }
    }
}
void left(int type,int r,int c){
    int t=c-1;
    if(c-1>=1){
        c--;
        while(bot[r][c].type==type){
            c--;
        }
        if(t!=c){
            if(type==1){bot[r][c].w_legal=1;}else{bot[r][c].b_legal=1;}
            bot[r][c].correlation[bot[r][c].c_n].r=r;
            bot[r][c].correlation[bot[r][c].c_n].c=t+1;
            bot[r][c].c_n++;
        }
    }
}
void right(int type,int r,int c){
    int t=c+1;
    if(c+1<9){
        c++;
        while(bot[r][c].type==type){
            c++;
        }
        if(t!=c){
            if(type==1){bot[r][c].w_legal=1;}else{bot[r][c].b_legal=1;}
            bot[r]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值