求助
查看原帖
求助
508593
DLDZD楼主2024/9/20 15:30
#include<bits/stdc++.h>
#define cc putchar(';');
#define xxx puts("Invalid command");
#define yes cout<<"yes";
#define no cout<<"no";
#define as cout<<"DEBUG";
#define itn int
using namespace std;
int n;
int x,y;
int ex,ey;
string mp[11][11];
bool over=false;
bool fan=false;
bool huang=false;
int bx[]={0,+1,+1,-1,-1,+0,+0,+1,-1};
int by[]={0,+1,-1,+1,-1,+1,-1,+0,+0};

int hx[]={0,-2,-2,-1,+1,+2,+2,+1,-1};
int hy[]={0,-1,+1,+2,+2,+1,-1,-2,-2};
int hpdx[]={0,-1,-1,0,0,1,1,0,0};
int hpdy[]={0,0,0,1,1,0,0,-1,-1};

int yx[]={0,-1,-1,-1,+1,+1,+1,+1,-1};
int yy[]={0,-1,+1,+1,+1,+1,-1,-1,-1};

int xx[]={0,+2,+2,-2,-2};
int xy[]={0,+2,-2,+2,-2};
void print(string s){
    if(s[0]=='r') cout<<"red ";
    if(s[0]=='b') cout<<"blue ";

    if(s[1]=='c') cout<<"car";
    if(s[1]=='h') cout<<"horse";
    if(s[1]=='e') cout<<"elephant";
    if(s[1]=='s') cout<<"guard";
    if(s[1]=='j') cout<<"captain";
    if(s[1]=='y') cout<<"duck";
    if(s[1]=='b') cout<<"soldier";
}
void init_red(){
    mp[0][0]="rc";mp[0][1]="rh";mp[0][2]="re";mp[0][3]="rs";
    mp[0][4]="rj";
    mp[0][5]="rs";mp[0][6]="re";mp[0][7]="rh";mp[0][8]="rc";
    mp[2][0]="ry";
    mp[2][8]="ry";
    mp[3][0]="rb";mp[3][2]="rb";mp[3][4]="rb";mp[3][6]="rb";mp[3][8]="rb";
}
void init_blue(){
    mp[9][0]="bc";mp[9][1]="bh";mp[9][2]="be";mp[9][3]="bs";
    mp[9][4]="bj";
    mp[9][5]="bs";mp[9][6]="be";mp[9][7]="bh";mp[9][8]="bc";
    mp[7][0]="by";
    mp[7][8]="by";
    mp[6][0]="bb";mp[6][2]="bb";mp[6][4]="bb";mp[6][6]="bb";mp[6][8]="bb";
}
int yuejie(int x,int y){
    return (x>9||x<0||y>8||y<0);
}
int kong(int x,int y){
    return (mp[x][y]=="00");
}
bool jj,sf;
void pd(){
    if(!sf){
        xxx huang=true; return ;
    }
    bool f=(!kong(ex,ey)&&mp[ex][ey][0]!=mp[x][y][0]);
    print(mp[x][y]);cc
    if(f) print(mp[ex][ey]);
    else cout<<"NA"; cc
    if(jj) yes
    else no cc
    if(f&&mp[ex][ey][1]=='j'){
        over=true;
        yes
    }
    else no
    mp[ex][ey]=mp[x][y];
    mp[x][y]="00";
    cout<<'\n';
    
}
void wsb(){
    sf=false;
    jj=false;
    string c=mp[x][y];
    int a,b;
    if(c[1]=='j') a=5,b=8;
    else if(c[1]=='s') a=1,b=4;
    else if(c[1]=='b') a=1,b=8;
    else return ;
    for(int i=a;i<=b;i++){
        if(yuejie(x+bx[i],y+by[i])) continue;
        if(yuejie(ex+bx[i],ey+by[i])) continue;
        if(x+bx[i]==ex&&y+by[i]==ey){
            sf=true;
        }
        if(!kong(ex+bx[i],ey+by[i])&&mp[ex+bx[i]][ey+by[i]][0]!=c[0]&&mp[ex+bx[i]][ey+by[i]][1]=='j'){
            jj=true;
        }
    }
    pd();
}
void xiang(){
    sf=false;
    jj=false;
    string c=mp[x][y];
    if(c[1]!='e') return ;
    for(int i=1;i<=4;i++){
        int ax=x+xx[i];
        int ay=y+xy[i];
        if(yuejie(ax,ay)) continue;
        if(yuejie(ex+xx[i],ey+xy[i])) continue;
        if(yuejie(ex+hx[i],ey+hy[i])) continue;
        if(ax==ex&&ay==ey){
            if(mp[x+xx[i]/2][y+xy[i]/2]=="00"){
                sf=true;
            }
            else{
                xxx huang=true; return ;
            }
        }
        if(mp[ax][ay][0]!=c[0]&&mp[ex+hx[i]][ey+hy[i]][1]=='j'){
            if(mp[ex+xx[i]/2][ey+xy[i]/2]=="00"){
                jj=true;
            }
        }
    }
    pd(); 
}
void ym(){
    sf=false;
    jj=false;
    string c=mp[x][y];
    if(c[1]!='y'&&c[1]!='h') return;
    for(int i=1;i<=8;i++){
        int ax=x+hx[i];
        int ay=y+hy[i];
        if(yuejie(ax,ay)||yuejie(ax+yx[i],ay+yy[i])) continue;
        if(yuejie(ex+hx[i],ey+hy[i])||yuejie(ex+hx[i]+yx[i],ey+hy[i]+yy[i])) continue;
        if(yuejie(ex+hpdx[i],ey+hpdy[i])) continue;
        if(c[1]=='y'&&x+yx[i]+hx[i]==ex&&y+yy[i]+hy[i]==ey){
            if(mp[x+hx[i]][y+hy[i]]=="00"&&mp[x+hpdx[i]][y+hpdy[i]]=="00"){
                sf=true;
            }
            else{
                xxx huang=true; return ;
            }
        }
        if((c[1]=='h')&&ax==ex&&y+hy[i]==ey){
            if(mp[x+hpdx[i]][y+hpdy[i]]=="00"){
                sf=true;
            }
            else{
                xxx huang=true; return ;
            }
        }
        if((c[1]=='h')&&mp[ax][ay][0]!=c[0]&&mp[ex+hx[i]][ey+hy[i]][1]=='j'){
            if(mp[ex+hpdx[i]][ey+hpdy[i]]=="00"){
                jj=true;
            }
        }
        if(c[1]=='y'&&mp[ax+yx[i]][ax+yy[i]][0]!=c[0]&&mp[ex+hx[i]+yx[i]][ey+hy[i]+yy[i]][0]=='j'){
            if(mp[ex+hx[i]][ey+hy[i]]=="00"){
                jj=true;
            }
        }
    }
    pd();
}
void che(){
    jj=false;
    if(x!=ex&&y!=ey){
        cout<<"Invalid command\n";
        huang=true;
        return ;
    }
    if(x==ex){
        for(int i=y+1;i<ey;i++){
            if(mp[x][y][0]==mp[x][i][0]){
                cout<<"Invalid command\n";
                huang=true;
                return ;
            }
        }
    }
    if(y==ey){
        for(int i=x+1;i<ex;i++){
            if(mp[x][y][0]==mp[i][y][0]){
                cout<<"Invalid command\n";
                huang=true;
                return ;
            }
        }
    }
    if(yuejie(x+1,y+1)||yuejie(x-1,y-1)) return ;
    for(int i=x+1;i<=9;i++){
        if(mp[i][ey]!="00"){
            if(mp[i][ey][0]!=mp[x][y][0]&&mp[i][ey][1]=='j'){
                jj=true;
            }
            break;
        }
    }
    for(int i=x-1;i>=0;i--){
        if(mp[i][ey]!="00"){
            if(mp[i][ey][0]!=mp[x][y][0]&&mp[i][ey][1]=='j'){
                jj=true;
            }
            break;
        }   
    }
    for(int i=y+1;i<=9;i++){
        if(mp[ex][i]!="00"){
            if(mp[ex][i][0]!=mp[x][y][0]&&mp[ex][i][1]=='j'){
                jj=true;
            }
            break;
        }
    }
    for(int i=y-1;i>=0;i--){
        if(mp[ex][i]!="00"){
            if(mp[ex][i][0]!=mp[x][y][0]&&mp[ex][i][1]=='j'){
                jj=true;
            }
            break;
        }
    }
    pd();
}
int main(){
    cin>>n;
    for(int i=0;i<=9;i++){
        for(int j=0;j<=8;j++){
            mp[i][j]="00";
        }
    }
    init_red();
    init_blue();
    for(int i=1;i<=n;i++){
        cin>>x>>y>>ex>>ey;
        huang=false;
        if(over||yuejie(x,y)||yuejie(ex,ey)||mp[x][y]=="00"||(x==ex&&y==ey)){
            xxx continue;
        }
        if(!fan){
            if(mp[x][y][0]=='b'||mp[ex][ey][0]=='r'){
                xxx continue;
            }
            wsb();
            xiang();
            ym();
            if(mp[x][y][1]=='c')che();
            if(!huang) fan=true;
            continue;
        }
        else if(fan){
            if(mp[x][y][0]=='r'||mp[ex][ey][0]=='b'){
                xxx continue;
            }
            wsb();
            xiang();
            ym();
            if(mp[x][y][1]=='c')che();
            if(!huang) fan=false;
            cout<<'\n';
            continue;
        }
    }/*
    for(int i=9;i>=0;i--){
        for(int j=0;j<=8;j++){
            cout<<mp[i][j]<<' ';
        }
        puts("");
    }*/
    return 0;
}
/*
5
0 0 1 0
9 8 8 8
1 0 1 1
8 8 9 8
1 1 9 1
*/
/*
100
0 0 1 0
9 8 8 8
1 0 1 1
8 8 9 8
1 1 9 1
9 8 8 8 
9 1 8 1
8 8 9 8 
8 1 8 4
9 8 8 8 
8 4 9 4
8 8 9 8
*/
2024/9/20 15:30
加载中...