第一个点数据肉眼对比过了,似乎无区别,但是WA on #1
查看原帖
第一个点数据肉眼对比过了,似乎无区别,但是WA on #1
1353330
K_J_M楼主2024/7/9 09:22
#include<bits/stdc++.h>
using namespace std;
int q,xs,ys,xt,yt;
int a[22][22];
int move[4]={0,1,-1};
int captx[6]={0,1,-1,0,0};
int capty[6]={0,0,0,1,-1};
int soldx[10]={0,1,-1,0,0,1,-1,1,-1};
int soldy[10]={0,0,0,1,-1,1,-1,-1,1};
int bposx,bposy,rposx,rposy;
int who,fail;//输了吗?0没有1输了 
void init(){
	who=1;//红方先手 
	for(int i=0;i<=3;i++){
		a[0][i]=i+1;
		a[9][i]=-i-1;
	}
	a[0][4]=5;a[9][4]=-5;
	for(int i=5;i<=8;i++){
		a[0][i]=9-i;
		a[9][i]=i-9;
	}
	for(int i=0;i<=8;i+=2){
		a[3][i]=6;
		a[6][i]=-6;
	}
	a[2][0]=a[2][8]=7;
	a[7][0]=a[7][8]=-7;
}
bool same(int sx,int sy,int ex,int ey){
	if(sx==ex&&sy==ey) return true;
	return false;
}
bool check(int x,int y){
	if(x<0||x>9||y<0||y>8) return false;
	return true;
}
bool pd(int sx,int sy,int ex,int ey){//棋子从(sx,sy)移到(ex,ey)是否合法 
	if(fail) return false; //已经输了 
	if(a[sx][sy]==0) return false;//没有棋子 
	if(a[sx][sy]*who<0) return false;//下的是别人的棋子不是自己的 
	if(a[ex][ey]*who>0) return false;//移动的终点是自己的棋子不是别人的 
	int ty=abs(a[sx][sy]);
	if(ty==1){//1车2马3象4士5王6兵7鸭
		if(sx!=ex&&sy!=ey) return false;
		if(sx==ex){
			if(sy<=ey){
				for(int i=sy+1;i<ey;i++){
					if(a[sx][i]!=0) return false;
				}
				return true;
			}else{
				for(int i=sy-1;i>ey;i--){
					if(a[sx][i]!=0) return false;
				}
				return true;
			}
		}else{
			if(sx<=ex){
				for(int i=sx+1;i<ex;i++){
					if(a[i][sy]!=0) return false;
				}
				return true;
			}else{
				for(int i=sx-1;i>ex;i--){
					if(a[i][sy]!=0) return false;
				} 
				return true;
			}
		}
	}
	if(ty==2){
		for(int i=1;i<=2;i++){
			for(int j=1;j<=2;j++){
				if(!check(sx+move[i],sy)||a[sx+move[i]][sy]==0){
					if(!check(sx+move[i]*2,sy+move[j])) continue;
					if(same(sx+move[i]*2,sy+move[j],ex,ey)) return true;
				}
				if(!check(sx,sy+move[j])||a[sx][sy+move[j]]==0){
					if(!check(sx+move[i],sy+move[j]*2)) continue;
					if(same(sx+move[i],sy+move[j]*2,ex,ey)) return true;
				}
			}
		}
		return false;
	}
	if(ty==3){
		for(int i=1;i<=2;i++){
			for(int j=1;j<=2;j++){
				if(!check(sx+move[i],sy+move[j])||a[sx+move[i]][sy+move[j]]==0){
					if(!check(sx+move[i]*2,sy+move[j]*2)) continue;
					if(same(sx+move[i]*2,sy+move[j]*2,ex,ey)) return true;
				}
			}
		}
		return false;
	}
	if(ty==4){
		for(int i=1;i<=2;i++){
			for(int j=1;j<=2;j++){
				if(!check(sx+move[i],sy+move[j])) continue;
				if(same(sx+move[i],sy+move[j],ex,ey)) return true;
			}
		}
		return false;
	}
	if(ty==5){
		for(int i=1;i<=4;i++){
			if(!check(sx+captx[i],sy+capty[i])) continue;
			if(same(sx+captx[i],sy+capty[i],ex,ey)) return true;
		}
		return false;
	}
	if(ty==7){
		for(int i=1;i<=2;i++){
			for(int j=1;j<=2;j++){
				if(!check(sx+move[i],sy)&&!check(sx+move[i]*2,sy+move[j])){
					if(!check(sx+move[i]*3,sy+move[j]*2)) continue;
					if(same(sx+move[i]*3,sy+move[j]*2,ex,ey)) return true;
				}
				if(!check(sx+move[i]*2,sy+move[j])){
					if(a[sx+move[i]][sy]==0){
						if(!check(sx+move[i]*3,sy+move[j]*2)) continue;
						if(same(sx+move[i]*3,sy+move[j]*2,ex,ey)) return true;
					}
				}
				if(!check(sx+move[i],sy)){
					if(a[sx+move[i]*2][sy+move[j]]==0){
						if(!check(sx+move[i]*3,sy+move[j]*2)) continue;
						if(same(sx+move[i]*3,sy+move[j]*2,ex,ey)) return true;
					}
				}
				if(a[sx+move[i]*2][sy+move[j]]==0&&a[sx+move[i]][sy]==0){
					if(!check(sx+move[i]*3,sy+move[j]*2)) continue;
					if(same(sx+move[i]*3,sy+move[sy]*2,ex,ey)) return true;
				}
				
				if(!check(sx+move[i],sy+move[j]*2)&&!check(sx,sy+move[j])){
					if(!check(sx+move[i]*2,sy+move[j]*3)) continue;
					if(same(sx+move[i]*2,sy+move[j]*3,ex,ey)) return true;
				}
				if(!check(sx+move[i],sy+move[j]*2)){
					if(a[sx][sy+move[j]]==0){
						if(!check(sx+move[i]*2,sy+move[j]*3)) continue;
						if(same(sx+move[i]*2,sy+move[j]*3,ex,ey)) return true;
					}
				}
				if(!check(sx,sy+move[j])){
					if(a[sx+move[i]][sy+move[j]*2]==0){
						if(!check(sx+move[i]*2,sy+move[j]*3)) continue;
						if(same(sx+move[i]*2,sy+move[j]*3,ex,ey)) return true;
					}
				}
				if(a[sx+move[i]][sy+move[j]*2]==0&&a[sx][sy+move[j]]==0){
					if(!check(sx+move[i]*2,sy+move[j]*3)) continue;
					if(same(sx+move[i]*2,sy+move[j]*3,ex,ey)) return true;
				}
			}
		}
		return false;
	}
	if(ty==6){
		for(int i=1;i<=8;i++){
			if(!check(sx+soldx[i],sy+soldy[i])) continue;
			if(same(sx+soldx[i],sy+soldy[i],ex,ey)) return true;
		}
		return false;
	}
}
string is(int x){
	if(x==1) return "red car";
	if(x==-1) return "blue car";
	if(x==2) return "red horse";
	if(x==-2) return "blue horse";
	if(x==3) return "red elephant";
	if(x==-3) return "blue elephant";
	if(x==4) return "red guard";
	if(x==-4) return "blue guard";
	if(x==5) return "red captain";
	if(x==-5) return "blue captain";
	if(x==6) return "red soldier";
	if(x==-6) return "blue soldier";
	if(x==7) return "red duck";
	if(x==-7) return "blue duck";
}
//1车2马3象4士5王6兵7鸭 
bool danger(int f,int x,int y){
	who=f==1? -1:1;
	for(int i=0;i<10;i++){
		for(int j=0;j<9;j++){
			if(a[i][j]*f<0){//是不是对方棋子 
				if(pd(i,j,x,y)) return true;
			}
		}
	}
	return false;
}
int main(){
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
	init();
	cin>>q;
	while(q--){
		cin>>xs>>ys>>xt>>yt;
		if(!pd(xs,ys,xt,yt)){
			cout<<"Invalid command"<<endl;
		}else{
			cout<<is(a[xs][ys])<<";";
			if(a[xt][yt]*who<0){
				cout<<is(a[xt][yt])<<";";
			}else{
				cout<<"NA;";
			}
			a[xt][yt]=a[xs][ys];
			a[xs][ys]=0;
			for(int i=0;i<10;i++){
				for(int j=0;j<9;j++){
					if(a[i][j]==5){
						rposx=i,rposy=j;
					}
					if(a[i][j]==-5){
						bposx=i,bposy=j;
					}
				}
			}//找出王	
			int cnt=0;
			for(int i=0;i<10;i++){
				for(int j=0;j<9;j++){
					if(a[i][j]==5||a[i][j]==-5) cnt++;
				}
			}
			fail=cnt==1? 1:0;
			int tmp=who;
			if(danger(1,rposx,rposy)||danger(-1,bposx,bposy)){
				cout<<"yes;";
			}else{
				cout<<"no;";
			}
			if(fail){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
			who=tmp;
			who=-who;
		}
	}
	return 0;
}
/*
阳历: 
18
0 0 7 0
9 0 8 0
0 1 1 3
0 2 2 0
0 3 1 2
0 4 0 3
9 4 8 4
3 2 2 3
7 0 4 2
7 0 5 3
9 2 7 4
2 0 4 3
9 1 8 3
4 3 6 6
7 4 9 2
8 4 9 4
6 6 9 4
9 8 8 8


ans:
Invalid command
Invalid command
Invalid command
Invalid command
red guard;NA;no;no
Invalid command
blue captain;NA;no;no
red soldier;NA;no;no
Invalid command
Invalid command
blue elephant;NA;no;no
red duck;NA;no;no
blue horse;NA;no;no
red duck;blue soldier;no;no
Invalid command
blue captain;NA;yes;no
red duck;blue captain;no;yes
Invalid command


我的out:
Invalid command
Invalid command
Invalid command
Invalid command
red guard;NA;no;no
Invalid command
blue captain;NA;no;no
red soldier;NA;no;no
Invalid command
Invalid command
blue elephant;NA;no;no
red duck;NA;no;no
blue horse;NA;no;no
red duck;blue soldier;no;no
Invalid command
blue captain;NA;yes;no
red duck;blue captain;no;yes
Invalid command


*/ 
2024/7/9 09:22
加载中...