大模拟WA求条我还是人吗
查看原帖
大模拟WA求条我还是人吗
639198
Steve_xh楼主2024/5/25 21:18

显然不是了

#include<iostream>
#define match(fx1,fy1) (((x1)+(fx1))==(x2))&&(((y1)+(fy1))==((y2)))
using namespace std;
namespace blue{
	const int captain	= 1;
	const int guard		= 2;
	const int elephant	= 3;
	const int horse		= 4;
	const int car		= 5;
	const int duck		= 6;
	const int soldier	= 7;
};
namespace red{
	const int captain	= 1|8;
	const int guard		= 2|8;
	const int elephant	= 3|8;
	const int horse		= 4|8;
	const int car		= 5|8;
	const int duck		= 6|8;
	const int soldier	= 7|8;
};
int n,mp[10][9];
bool won=false;
pair<int,int> capxy[2];
bool huihe=true;
inline void init(){
	mp[0][0]=red::car,mp[0][1]=red::horse,mp[0][2]=red::elephant,mp[0][3]=red::guard,mp[0][4]=red::captain,mp[0][5]=red::guard,mp[0][6]=red::elephant,mp[0][7]=red::horse,mp[0][8]=red::car;
	mp[2][0]=mp[0][8]=red::duck;
	mp[3][0]=mp[3][1]=mp[3][2]=mp[3][3]=mp[3][4]=mp[3][5]=mp[3][6]=mp[3][7]=mp[3][8]=red::soldier;
	capxy[1]=make_pair(0,4);
	
	mp[6][0]=mp[6][1]=mp[6][2]=mp[6][3]=mp[6][4]=mp[6][5]=mp[6][6]=mp[6][7]=mp[6][8]=blue::soldier;
	mp[7][0]=mp[7][8]=blue::duck;
	mp[9][0]=blue::car,mp[9][1]=blue::horse,mp[9][2]=blue::elephant,mp[9][3]=blue::guard,mp[9][4]=blue::captain,mp[9][5]=blue::guard,mp[9][6]=blue::elephant,mp[9][7]=blue::horse,mp[9][8]=blue::car;
	capxy[0]=make_pair(9,4);
}
inline bool same_cp(int x,int y){
	return x&&y&&!((x&8)^(y&8));
}
inline int get(int x){
	return (x&7);
}
inline bool out_of_map(int x,int y){
	return (x<0)||(y<0)||(x>=10)||(y>=9);
}
inline bool fail(int x1,int y1,int x2,int y2){
//	cerr<<"in\n";
	if(won)
		return true;
	if(out_of_map(x1,y1)||out_of_map(x2,y2)||!mp[x1][y1]||(same_cp(mp[x1][y1],mp[x2][y2])&&mp[x2][y2]))
		return true;
	if(get(mp[x1][y1])==1)
		return !(match(1,0)||match(-1,0)||match(0,1)||match(0,-1));
	if(get(mp[x1][y1])==2)
		return !(match(1,1)||match(-1,-1)||match(-1,1)||match(1,-1));
	if(get(mp[x1][y1])==3){
		for(int i:{-1,1})
			for(int j:{-1,1})
				if(match(i<<1,j<<1))
					return mp[x1+i][y1+j];
		return true;
	}
	if(get(mp[x1][y1])==4){
//		cerr<<"in horse\n";
		for(int i:{-1,1})
			for(int j:{-1,1}){
				if(match(i<<1,j))
					return mp[x1+i][y1];
				if(match(i,j<<1))
					return mp[x1][y1+j];
			}
		return true;
	}
	if(get(mp[x1][y1])==5){
//		cerr<<"car\n";
		if(x1==x2){
//			cerr<<"x1==x2\n";
			for(int i=min(y1,y2)+1;i<max(y1,y2);i++)
				if(mp[x1][i])
					return true;
			return false;
		}else if(y1==y2){
//			cerr<<"y1==y2\n";
			for(int i=min(x1,x2)+1;i<max(x1,x2);i++)
				if(mp[i][y1])
					return true;
			return false;
		}else
			return true;
	}
	if(get(mp[x1][y1])==6){
		for(int i:{-1,1})
			for(int j:{-1,1}){
				if(match(i*3,j<<1))
					return mp[x1+(i<<1)][y1+j]||mp[x1+i][y1];
				if(match(i<<1,j*3))
					return mp[x1+i][y1+(j<<1)]||mp[x1][y1+j];
			}
		return true;
	}
	if(get(mp[x1][y1])==7){
		for(pair<int,int> i:{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1),make_pair(1,1),make_pair(-1,-1),make_pair(1,-1),make_pair(-1,1)})
			if(match(i.first,i.second))
				return false;
		return true;
	}
	return true;
}
const string chess_name[8][2]={
	{"",""},
	{"blue captain"	,"red captain"	},
	{"blue guard"	,"red guard"	},
	{"blue elephant","red elephant"	},
	{"blue horse"	,"red horse"	},
	{"blue car"		,"red car"		},
	{"blue duck"	,"red duck"		},
	{"blue soldier"	,"red soldier"	},
};
int main(){
	freopen("P5380.in","r",stdin);
	freopen("P5380.out","w",stdout);
	init();
	cin.tie(0)->sync_with_stdio(false);
	cin>>n;
//	cerr<<mp[0][3]<<'\n';
	for(int i=1,x1,y1,x2,y2;i<=n;i++){
		cin>>x1>>y1>>x2>>y2;
		if(((mp[x1][y1]>8)^huihe)||fail(x1,y1,x2,y2)){
			cout<<"Invalid command\n";
			continue;
		}
		huihe=!huihe;
		cout<<chess_name[get(mp[x1][y1])][mp[x1][y1]>8]<<';';
		if(!mp[x2][y2])
			cout<<"NA;";
		else
			cout<<chess_name[get(mp[x2][y2])][mp[x2][y2]>8]<<';';
		if(get(mp[x2][y2])==1)
			won=true;
		if(get(mp[x1][y1])==1)
			capxy[mp[x1][y1]>8]=make_pair(x2,y2);
		mp[x2][y2]=mp[x1][y1];
		mp[x1][y1]=0;
		if(won){
			cout<<"no;yes\n";
			continue;
		}
		for(int i=0;i<10;i++)
			for(int j=0;j<9;j++)
				if(!fail(i,j,capxy[mp[i][j]<8].first,capxy[mp[i][j]<8].second)){
					cout<<"yes;no\n";
					goto runend;
				}
		cout<<"no;no\n";
		runend:;
	}
	return 0;
}
2024/5/25 21:18
加载中...