第二个测试点两百多行出了问题,会把合法的判成不合法的。看好几天了也没看出来问题。崩溃了
//王(captain)1 8
//士(guard)2 9
//象(elephant)3 10
//马(horse)4 11
//车(car)5 12
//鸭(duck)6 13
//兵(soldier)7 14
#include <stdio.h>
#include <iostream>
using namespace std;
#define map mp
int turnn=1,ended=0;
int map[12][12]=
{
{0,0,0,0,0,0,0,0,0,0},
{0,12,11,10,9,8,9,10,11,12},
{0,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{0,13,-1,-1,-1,-1,-1,-1,-1,13},
{0,14,-1,14,-1,14,-1,14,-1,14},
{0,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{0,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{0,7,-1,7,-1,7,-1,7,-1,7},
{0,6,-1,-1,-1,-1,-1,-1,-1,6},
{0,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{0,5,4,3,2,1,2,3,4,5},
};
void move(int x1,int y1,int x2,int y2)
{
map[11-x2][y2]=map[11-x1][y1];
map[11-x1][y1]=-1;
}
bool serchking()
{
int k=0;
for(int i=1;i<=10;i++)
for(int j=1;j<=9;j++)
if(map[i][j]==1||map[i][j]==8)k++;
return k==2;
}
bool correctmove(int x11,int y1,int x22,int y2){
int x1=11-x11,x2=11-x22;
int ad=map[x1][y1],td=map[x2][y2];
if(turnn==1)
{
if(ad>=1&&ad<=7)
{
if(td==-1||td>=8)
{
if(ad==1)
{
if((abs(x1-x2)==1&&abs(y1-y2)==0)||(abs(x1-x2)==0&&abs(y1-y2)==1))
{
return 1;
}else return 0;
}
if(ad==2)
{
if(abs(x1-x2)==1&&abs(y1-y2)==1)
{
return 1;
}else return 0;
}
if(ad==3)
{
if(abs(x1-x2)==2&&abs(y1-y2)==2)
{
if(x1-x2==2&&y1-y2==2)//左上
{
if(map[x1-1][y1-1]==-1)
{
return 1;
}else return 0;
}
if(x1-x2==2&&y1-y2==-2)//右上
{
if(map[x1-1][y1+1]==-1)
{
return 1;
}else return 0;
}
if(x1-x2==-2&&y1-y2==2)//左下
{
if(map[x1+1][y1-1]==-1)
{
return 1;
}else return 0;
}
if(x1-x2==-2&&y1-y2==-2)//右下
{
if(map[x1+1][y1+1]==-1)
{
return 1;
}else return 0;
}
}else return 0;
}
if(ad==4)
{
if(x1-2==x2&&y1-1==y2)//左上
{
if(map[x1-1][y1]==-1)
{
return 1;
}else return 0;
}else if(x1-1==x2&&y1-2==y2)//左上
{
if(map[x1][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1+1==x2&&y1-2==y2)//左下
{
if(map[x1][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1-1==y2)//左下
{
if(map[x1+1][y1]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1+1==y2)//右下
{
if(map[x1+1][y1]==-1)
{
return 1;
}else return 0;
}else if(x1+1==x2&&y1+2==y2)//右下
{
if(map[x1][y1+1]==-1)
{
return 1;
}else return 0;
}else if(x1-1==x2&&y1+2==y2)//右上
{
if(map[x1][y1+1]==-1)
{
return 1;
}else return 0;
}else if(x1-2==x2&&y1+1==y2)//右上
{
if(map[x1-1][y1]==-1)
{
return 1;
}else return 0;
}else return 0;
}
if(ad==5)
{
if(x1==x2)
{
if(y1<y2)
{
for(int i=y1+1;i<=y2-1;i++)
{
if(map[x1][i]!=-1)return 0;
}
}else
{
for(int i=y2+1;i<=y1-1;i++)
{
if(map[x1][i]!=-1)return 0;
}
}
return 1;
}else if(y1==y2)
{
if(x1<x2)
{
for(int i=x1+1;i<=x2-1;i++)
{
if(map[i][y1]!=-1)return 0;
}
}else
{
for(int i=x2+1;i<=x1-1;i++)
{
if(map[i][y1]!=-1)return 0;
}
}
return 1;
}else return 0;
}
if(ad==6)
{
if(x1-3==x2&&y1-2==y2)//左上
{
if(map[x1-1][y1]==-1&&map[x1-2][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1-2==x2&&y1-3==y2)//左上
{
if(map[x1][y1-1]==-1&&map[x1-1][y1-2]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1-3==y2)//左下
{
if(map[x1][y1-1]==-1&&map[x1+1][y1-2]==-1)
{
return 1;
}else return 0;
}else if(x1+3==x2&&y1-2==y2)//左下
{
if(map[x1+1][y1]==-1&&map[x1+2][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1+3==x2&&y1+2==y2)//右下
{
if(map[x1+1][y1]==-1&&map[x1+2][y1+1]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1+3==y2)//右下
{
if(map[x1][y1+1]==-1&&map[x1+1][y1+2]==-1)
{
return 1;
}else return 0;
}else if(x1-2==x2&&y1+3==y2)//右上
{
if(map[x1][y1+1]==-1&&map[x1-1][y1+2]==-1)
{
return 1;
}else return 0;
}else if(x1-3==x2&&y1+2==y2)//右上
{
if(map[x1-1][y1]==-1&&map[x1-2][y1+1]==-1)
{
return 1;
}else return 0;
}else return 0;
}
if(ad==7)
{
if((abs(x1-x2)==1||abs(x1-x2)==0)&&(abs(y1-y2)==1||abs(y1-y2)==0))
{
return 1;
}
else return 0;
}
}else return 0;
}else return 0;
}
if(turnn==-1)
{
if(ad>=8&&ad<=14)
{
if(td==-1||(td>=1&&td<=7))
{
if(ad==8)
{
if((abs(x1-x2)==1&&abs(y1-y2)==0)||(abs(x1-x2)==0&&abs(y1-y2)==1))
{
return 1;
}else return 0;
}
if(ad==9)
{
if(abs(x1-x2)==1&&abs(y1-y2)==1)
{
return 1;
}else return 0;
}
if(ad==10)
{
if(abs(x1-x2)==2&&abs(y1-y2)==2)
{
if(x1-x2==2&&y1-y2==2)//左上
{
if(map[x1-1][y1-1]==-1)
{
return 1;
}else return 0;
}
if(x1-x2==2&&y1-y2==-2)//右上
{
if(map[x1-1][y1+1]==-1)
{
return 1;
}else return 0;
}
if(x1-x2==-2&&y1-y2==2)//左下
{
if(map[x1+1][y1-1]==-1)
{
return 1;
}else return 0;
}
if(x1-x2==-2&&y1-y2==-2)//右下
{
if(map[x1+1][y1+1]==-1)
{
return 1;
}else return 0;
}
}else return 0;
}
if(ad==11)
{
if(x1-2==x2&&y1-1==y2)//左上
{
if(map[x1-1][y1]==-1)
{
return 1;
}else return 0;
}else if(x1-1==x2&&y1-2==y2)//左上
{
if(map[x1][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1+1==x2&&y1-2==y2)//左下
{
if(map[x1][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1-1==y2)//左下
{
if(map[x1+1][y1]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1+1==y2)//右下
{
if(map[x1+1][y1]==-1)
{
return 1;
}else return 0;
}else if(x1+1==x2&&y1+2==y2)//右下
{
if(map[x1][y1+1]==-1)
{
return 1;
}else return 0;
}else if(x1-1==x2&&y1+2==y2)//右上
{
if(map[x1][y1+1]==-1)
{
return 1;
}else return 0;
}else if(x1-2==x2&&y1+1==y2)//右上
{
if(map[x1-1][y1]==-1)
{
return 1;
}else return 0;
}else return 0;
}
if(ad==12)
{
if(x1==x2)
{
if(y1<y2)
{
for(int i=y1+1;i<=y2-1;i++)
{
if(map[x1][i]!=-1)return 0;
}
}else
{
for(int i=y2+1;i<=y1-1;i++)
{
if(map[x1][i]!=-1)return 0;
}
}
return 1;
}else if(y1==y2)
{
if(x1<x2)
{
for(int i=x1+1;i<=x2-1;i++)
{
if(map[i][y1]!=-1)return 0;
}
}else
{
for(int i=x2+1;i<=x1-1;i++)
{
if(map[i][y1]!=-1)return 0;
}
}
return 1;
}else return 0;
}
if(ad==13)
{
if(x1-3==x2&&y1-2==y2)//左上
{
if(map[x1-1][y1]==-1&&map[x1-2][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1-2==x2&&y1-3==y2)//左上
{
if(map[x1][y1-1]==-1&&map[x1-1][y1-2]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1-3==y2)//左下
{
if(map[x1][y1-1]==-1&&map[x1+1][y1-2]==-1)
{
return 1;
}else return 0;
}else if(x1+3==x2&&y1-2==y2)//左下
{
if(map[x1+1][y1]==-1&&map[x1+2][y1-1]==-1)
{
return 1;
}else return 0;
}else if(x1+3==x2&&y1+2==y2)//右下
{
if(map[x1+1][y1]==-1&&map[x1+2][y1+1]==-1)
{
return 1;
}else return 0;
}else if(x1+2==x2&&y1+3==y2)//右下
{
if(map[x1][y1+1]==-1&&map[x1+1][y1+2]==-1)
{
return 1;
}else return 0;
}else if(x1-2==x2&&y1+3==y2)//右上
{
if(map[x1][y1+1]==-1&&map[x1-1][y1+2]==-1)
{
return 1;
}else return 0;
}else if(x1-3==x2&&y1+2==y2)//右上
{
if(map[x1-1][y1]==-1&&map[x1-2][y1+1]==-1)
{
return 1;
}else return 0;
}else return 0;
}
if(ad==14)
{
if((abs(x1-x2)==1||abs(x1-x2)==0)&&(abs(y1-y2)==1||abs(y1-y2)==0))
{
return 1;
}
else return 0;
}
}else return 0;
}else return 0;
}
}
bool checkmate(){
for(int i1=1;i1<=10;i1++)
{
for(int j1=1;j1<=9;j1++)
{
for(int i2=1;i2<=10;i2++)
{
for(int j2=1;j2<=9;j2++)
{
if(i1==i2&&j1==j2)break;
if(correctmove(i1,j1,i2,j2))
{
if(map[11-i2][j2]==1||map[11-i2][j2]==8)
return 1;
}
turnn=-turnn;
if(correctmove(i1,j1,i2,j2))
{
if(map[11-i2][j2]==1||map[11-i2][j2]==8)
return 1;
}
turnn=-turnn;
}
}
}
}
return 0;
}
void printchess(int n){
if(n==1)cout<<"red captain";
if(n==2)cout<<"red guard";
if(n==3)cout<<"red elephant";
if(n==4)cout<<"red horse";
if(n==5)cout<<"red car";
if(n==6)cout<<"red duck";
if(n==7)cout<<"red soldier";
if(n==8)cout<<"blue captain";
if(n==9)cout<<"blue guard";
if(n==10)cout<<"blue elephant";
if(n==11)cout<<"blue horse";
if(n==12)cout<<"blue car";
if(n==13)cout<<"blue duck";
if(n==14)cout<<"blue soldier";
}
void chessgo(int x1,int y1,int x2,int y2){
if(correctmove(x1,y1,x2,y2)==1&&ended==0)
{
printchess(map[11-x1][y1]);
cout<<";";
if(map[11-x2][y2]==-1)
{
cout<<"NA";
}else printchess(map[11-x2][y2]);
cout<<";";
move(x1,y1,x2,y2);
turnn=-turnn;
if(checkmate())cout<<"yes;";
else cout<<"no;";
if(serchking()==1)cout<<"no";
else
{
cout<<"yes";
ended=1;
}
cout<<endl;
return;
}else
{
cout<<"Invalid command"<<endl;
return;
}
}
int main(){
int qs;
cin>>qs;
while(qs--){
int qq,ww,ee,rr;
cin>>qq>>ww>>ee>>rr;
chessgo(qq+1,ww+1,ee+1,rr+1);
}
return 0;
}