告诫后人
查看原帖
告诫后人
360930
Jairon314楼主2021/3/22 21:17

告诫后人\textbf {\large 告诫后人}

切记!写这种码农题的时候不要一直不停的写下去,要尽量写的简单易懂,不要写的让自己都看不懂!

写了这题我才知道拥有一个良好码风的重要性/kk我那天从下午三点写到晚上十一点,最后好不容易过了样例,交上去只过了样例1.../kk后来好不容易改了一些明显的错误以后,样例2还是从将近900多行的位置开始错......我今天又想起来这道题,发现当时的代码我自己都快看不懂了。于是在这里告诫后人。

这就是拥有一个坏码风的结果

我还决定放一下自己1000多行还停留在25分的代码,以此来警戒大家。我放自己的代码,已经不报任何的希望有人帮忙找错了,希望大家能吸取我的教训。 /ll

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

#define maxn 1000010
#define without w
#define RedCar c
#define RedDuck d
#define RedSoldier s
#define RedHorse h
#define RedElephant e
#define RedGuard g
#define RedCaptain p
#define BlueCar C
#define BlueDuck D
#define BlueSoldier S
#define BlueHorse H
#define BlueElephant E
#define BlueGuard G
#define BlueCaptain P

bool FLAG=0;//?D??ó??·ê?·??áê?
char map1[10][10];
int Q,xx1,yy1,xx2,yy2;

void PutChessman();

void init();

void check2(int xx,int yy);

bool check(int xx,int yy);

bool work2(int xx1,int yy1,int xx2,int yy2);

bool danger();

bool work(int xx1,int yy1,int xx2,int yy2,int i);

//?÷oˉêy 
int main(){
	PutChessman();
	init();
	return 0;
}

//?D????é?
//oìé?·μ??1,à?é?·μ??0
//w·μ??0
bool check(int xx,int yy){
	char ch1=map1[xx][yy]; 
	if(ch1=='c'||ch1=='d'||ch1=='s'||ch1=='h'||ch1=='e'||ch1=='g'||ch1=='p'){
		return 1;
	}
	//cout<<map1[xx][yy]<<endl;
	return 0;
}

//?D??ààDí 
void check2(int xx,int yy){
	if(map1[xx][yy]=='w'){
		printf("NA;");
	}
	else{
		if(map1[xx][yy]=='c'){
			printf("red car;");
		}
		else if(map1[xx][yy]=='C'){
			printf("blue car;");
		}
		else if(map1[xx][yy]=='d'){
			printf("red duck;");
		}
		else if(map1[xx][yy]=='D'){
			printf("blue duck;");
		}
		else if(map1[xx][yy]=='s'){
			printf("red soldier;");
		}
		else if(map1[xx][yy]=='S'){
			printf("blue soldier;");
		}
		else if(map1[xx][yy]=='h'){
			printf("red horse;");
		}
		else if(map1[xx][yy]=='H'){
			printf("blue horse;");
		}
		else if(map1[xx][yy]=='e'){
			printf("red elephant;");
		}
		else if(map1[xx][yy]=='E'){
			printf("blue elephant;");
		}
		else if(map1[xx][yy]=='g'){
			printf("red guard;");
		}
		else if(map1[xx][yy]=='G'){
			printf("blue guard;");
		}
		else if(map1[xx][yy]=='p'){
			printf("red captain;");
			FLAG=1;
		}
		else if(map1[xx][yy]=='P'){
			printf("blue captain;");
			FLAG=1;
		}
	}
}

//?D??2ù×÷ê?·?o?àí
bool work(int xx1,int yy1,int xx2,int yy2,int i){
	int x_=xx1,y_=yy1,x__=xx2,y__=yy2;
	swap(xx1,yy1);
	xx1=8-xx1;
	swap(xx2,yy2);
	xx2=8-xx2;
	if(map1[xx1][yy1]=='w'){
		//cout<<1<<endl;
		return false;
	}
	else if(FLAG==1){
		//cout<<1<<endl;
		return false;
	}
	else if(i%2==1&&!check(xx1,yy1)){
		//cout<<1<<endl;
		return false;
	}
	else if(i%2==0&&check(xx1,yy1)){
		//cout<<1<<endl;
		return false;
	}
	else{
		char ch1=map1[xx1][yy1];
		if(ch1=='c'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				for(int i=min(yy1,yy2)+1;i<max(yy1,yy2);i++){
					if(map1[xx1][i]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			else if(yy1==yy2){
				for(int i=min(xx1,xx2)+1;i<max(xx1,xx2);i++){
					if(map1[i][yy1]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("red car;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='C'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				for(int i=min(yy1,yy2)+1;i<max(yy1,yy2);i++){
					if(map1[xx1][i]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			else if(yy1==yy2){
				for(int i=min(xx1,xx2)+1;i<max(xx1,xx2);i++){
					if(map1[i][yy1]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("blue car;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='p'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				if(abs(yy1-yy2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			else if(yy1==yy2){
				if(abs(xx1-xx2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			if((check(xx2,yy2))&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("red captain;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='P'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				if(abs(yy1-yy2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			else if(yy1==yy2){
				if(abs(xx1-xx2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("blue captain;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='g'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)>1||abs(yy1-yy2)>1){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("red guard;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='G'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)>1||abs(yy1-yy2)>1){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("blue guard;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='e'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2||abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			else if(map1[(xx1+xx2)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("red elephant;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='E'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2||abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			else if(map1[(xx1+xx2)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("blue elephant;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='h'){
			//cout<<xx1<<" "<<yy1<<endl;
			//cout<<xx2<<" "<<yy2<<endl;
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(map1[(xx1+xx2+1)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("red horse;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='H'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(map1[(xx1+xx2+1)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("blue horse;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='s'){
			if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=0){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=0){
				//cout<<1<<endl;
				return false;
			}
			if((check(xx2,yy2))&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("red soldier;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='S'){
			if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=0){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=0){
				//cout<<1<<endl;
				return false;
			}
			if((!check(xx2,yy2))&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("blue soldier;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='d'){
			int sx,sy;
			//cout<<xx1<<" "<<xx2<<" "<<yy1<<" "<<yy2<<endl;
			if(xx1>xx2&&yy1>yy2){
				sx=-1;
				sy=-1;
			}
			else if(xx1<xx2&&yy1<yy2){
				sx=1;
				sy=1;
			}
			else if(xx1>xx2&&yy1<yy2){
				sx=-1;
				sy=1;
			}
			else if(xx1<xx2&&yy1>yy2){
				sx=1;
				sy=-1;
			}
			if(xx1+sx*3==xx2&&yy1+sy*2==yy2&&(map1[xx1+sx*2][yy1+sy*1]!='w'||map1[xx1+sx*1][yy1]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1+sx*2==xx2&&yy1+sy*3==yy2&&(map1[xx1+sx*1][yy1+sy*2]!='w'||map1[xx1][yy1+sy]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2&&abs(xx1-xx2)!=3){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=2&&abs(yy1-yy2)!=3){
				//cout<<1<<endl;
				return false;
				/*----------------------------------------------------------------*/
			}
			else if(abs(xx1-xx2)==abs(yy1-yy2)){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("red duck;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		else if(ch1=='D'){
			int sx,sy;
			//cout<<xx1<<" "<<xx2<<" "<<yy1<<" "<<yy2<<endl;
			if(xx1>xx2&&yy1>yy2){
				sx=-1;
				sy=-1;
			}
			else if(xx1<xx2&&yy1<yy2){
				sx=1;
				sy=1;
			}
			else if(xx1>xx2&&yy1<yy2){
				sx=-1;
				sy=1;
			}
			else if(xx1<xx2&&yy1>yy2){
				sx=1;
				sy=-1;
			}
			if(xx1+sx*3==xx2&&yy1+sy*2==yy2&&(map1[xx1+sx*2][yy1+sy*1]!='w'||map1[xx1+sx*1][yy1]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1+sx*2==xx2&&yy1+sy*3==yy2&&(map1[xx1+sx*1][yy1+sy*2]!='w'||map1[xx1][yy1+sy]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2&&abs(xx1-xx2)!=3){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=2&&abs(yy1-yy2)!=3){
				//cout<<1<<endl;
				return false;
				/*----------------------------------------------------------------*/
			}
			else if(abs(xx1-xx2)==abs(yy1-yy2)){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			swap(map1[xx1][yy1],map1[xx2][yy2]);
			printf("blue duck;");
			check2(xx1,yy1);
			map1[xx1][yy1]='w';
		}
		/*-----------------------------------------------------------------------*/
	}
	if(danger()/*?D??ê?·????ü*/){
		/*-----------------------------------------------------------------------*/
		printf("yes;");
	}
	else printf("no;");
	if(FLAG==1){
		printf("yes\n");
	}
	else printf("no\n");
	return true;
}

//?D??2ù×÷ê?·?o?àí
bool work2(int xx1,int yy1,int xx2,int yy2){
	if(1){
		char ch1=map1[xx1][yy1];
		//cout<<ch1<<endl;
		if(ch1=='c'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				for(int i=min(yy1,yy2)+1;i<max(yy1,yy2);i++){
					if(map1[xx1][i]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			else if(yy1==yy2){
				for(int i=min(xx1,xx2)+1;i<max(xx1,xx2);i++){
					if(map1[i][yy1]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='C'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				for(int i=min(yy1,yy2)+1;i<max(yy1,yy2);i++){
					if(map1[xx1][i]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			else if(yy1==yy2){
				for(int i=min(xx1,xx2)+1;i<max(xx1,xx2);i++){
					if(map1[i][yy1]!='w'){
						//cout<<1<<endl;
						return false;
					}
				}
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='p'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				if(abs(yy1-yy2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			else if(yy1==yy2){
				if(abs(xx1-xx2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			if((check(xx2,yy2))&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='P'){
			if(xx1!=xx2&&yy1!=yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1==xx2){
				if(abs(yy1-yy2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			else if(yy1==yy2){
				if(abs(xx1-xx2)!=1){
					//cout<<1<<endl;
					return false;
				}
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='g'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)>1||abs(yy1-yy2)>1){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='G'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)>1||abs(yy1-yy2)>1){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='e'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2||abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			else if(map1[(xx1+xx2)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='E'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2||abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			else if(map1[(xx1+xx2)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='h'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(map1[(xx1+xx2+1)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='H'){
			if(xx1==xx2||yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=2){
				//cout<<1<<endl;
				return false;
			}
			if(map1[(xx1+xx2+1)/2][(yy1+yy2)/2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='s'){
			if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=0){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=0){
				//cout<<1<<endl;
				return false;
			}
			if((check(xx2,yy2))&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='S'){
			if(xx1==xx2&&yy1==yy2){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=1&&abs(xx1-xx2)!=0){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=1&&abs(yy1-yy2)!=0){
				//cout<<1<<endl;
				return false;
			}
			if((!check(xx2,yy2))&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		else if(ch1=='d'){
			int sx,sy;
			//cout<<xx1<<" "<<xx2<<" "<<yy1<<" "<<yy2<<endl;
			if(xx1>xx2&&yy1>yy2){
				sx=-1;
				sy=-1;
			}
			else if(xx1<xx2&&yy1<yy2){
				sx=1;
				sy=1;
			}
			else if(xx1>xx2&&yy1<yy2){
				sx=-1;
				sy=1;
			}
			else if(xx1<xx2&&yy1>yy2){
				sx=1;
				sy=-1;
			}
			if(xx1+sx*3==xx2&&yy1+sy*2==yy2&&(map1[xx1+sx*2][yy1+sy*1]!='w'||map1[xx1+sx*1][yy1]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1+sx*2==xx2&&yy1+sy*3==yy2&&(map1[xx1+sx*1][yy1+sy*2]!='w'||map1[xx1][yy1+sy]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2&&abs(xx1-xx2)!=3){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=2&&abs(yy1-yy2)!=3){
				//cout<<1<<endl;
				return false;
				/*----------------------------------------------------------------*/
			}
			else if(abs(xx1-xx2)==abs(yy1-yy2)){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			//cout<<xx1<<" "<<xx2<<";";
			return true;
		}
		else if(ch1=='D'){
			int sx,sy;
			//cout<<xx1<<" "<<xx2<<" "<<yy1<<" "<<yy2<<endl;
			if(xx1>xx2&&yy1>yy2){
				sx=-1;
				sy=-1;
			}
			else if(xx1<xx2&&yy1<yy2){
				sx=1;
				sy=1;
			}
			else if(xx1>xx2&&yy1<yy2){
				sx=-1;
				sy=1;
			}
			else if(xx1<xx2&&yy1>yy2){
				sx=1;
				sy=-1;
			}
			if(xx1+sx*3==xx2&&yy1+sy*2==yy2&&(map1[xx1+sx*2][yy1+sy*1]!='w'||map1[xx1+sx*1][yy1]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1+sx*2==xx2&&yy1+sy*3==yy2&&(map1[xx1+sx*1][yy1+sy*2]!='w'||map1[xx1][yy1+sy]!='w')){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(xx1-xx2)!=2&&abs(xx1-xx2)!=3){
				//cout<<1<<endl;
				return false;
			}
			else if(abs(yy1-yy2)!=2&&abs(yy1-yy2)!=3){
				//cout<<1<<endl;
				return false;
				/*----------------------------------------------------------------*/
			}
			else if(abs(xx1-xx2)==abs(yy1-yy2)){
				//cout<<1<<endl;
				return false;
			}
			else if(xx1<0||xx1>8||yy1<0||yy1>9){
				//cout<<1<<endl;
				return false;
			}
			if(!check(xx2,yy2)&&map1[xx2][yy2]!='w'){
				//cout<<1<<endl;
				return false;
			}
			//cout<<1<<endl;
			return true;
		}
		/*-----------------------------------------------------------------------*/
	}
	return false;
}

bool danger(){
	int redx=0,redy=0;
	int bluex=0,bluey=0;
	for(int i=0;i<=8;i++){
		for(int j=0;j<=9;j++){
			if(map1[i][j]=='p'){
				redx=i;
				redy=j;
			}
			else if(map1[i][j]=='P'){
				bluex=i;
				bluey=j;
			}
			if(redx&&redy&&bluex&&bluey){
				i=10;
				j=10;
			}
		}
	}
	for(int i=0;i<=8;i++){
		for(int j=0;j<=9;j++){
			if(map1[i][j]!='w'&&map1[i][j]!='p'&&map1[i][j]!='P'){
				if(check(i,j)){
					//cout<<map1[i][j]<<endl;
					if(work2(i,j,bluex,bluey)){
						return 1;
					}
				}
				else if(!check(i,j)){
					if(work2(i,j,redx,redy)){
						return 1;
					}
				}
			}
		}
	}
	return 0;
}

//ê?è?
void init(){
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++){
		scanf("%d%d%d%d",&xx1,&yy1,&xx2,&yy2);
		if(!work(xx1,yy1,xx2,yy2,i)){
			i--;
			Q--;
			printf("Invalid command\n");
		}
		else{
			/*-------------------------------------------------------------------*/
		}
		/*
		for(int i=0;i<=8;i++){
			for(int j=0;j<=9;j++){
				cout<<map1[i][j]<<" ";
			}
			printf("\n");
		}
		*/
	}
}

//3?ê??ˉ???ì
void PutChessman(){
	for(int i=0;i<=10;i++){
		for(int j=0;j<=10;j++){
			map1[i][j]='w';
		}
	}
	map1[0][0]=map1[8][0]='c';
	map1[0][2]=map1[8][2]='d';
	map1[0][3]=map1[2][3]=map1[4][3]=map1[6][3]=map1[8][3]='s';
	map1[1][0]=map1[7][0]='h';
	map1[2][0]=map1[6][0]='e';
	map1[3][0]=map1[5][0]='g';
	map1[4][0]='p';
	map1[0][9]=map1[8][9]='C';
	map1[0][7]=map1[8][7]='D';
	map1[0][6]=map1[2][6]=map1[4][6]=map1[6][6]=map1[8][6]='S';
	map1[1][9]=map1[7][9]='H';
	map1[2][9]=map1[6][9]='E';
	map1[3][9]=map1[5][9]='G';
	map1[4][9]='P';
}
/*
9
0 0 0 1
0 9 0 8
0 1 3 1
0 8 3 8
3 1 3 8
8 9 8 8
3 8 3 9
8 8 4 8
3 9 4 9
red car;NA;no;no;
blue car;NA;no;no;
red car;NA;no;no;
blue car;NA;no;no;
red car;blue car;no;no;
blue car;NA;no;no;
red car;blue guard;no;no;
blue car;NA;no;no;
red car;blue captain;no;yes;
*/
/*
6 0 4 2
*/
//!!!!!!

这份代码经过多次复制,注释已经丢失了。

我决定痛改前非,去学习一种好的码风。

2021/3/22 21:17
加载中...