//搜索题,王用宽搜解决,后用点和点的斜率解决,只有两种情况,要么1,要么2。 //车直线判断即可,要么1,要么2。 //象斜率判断加所在格子的黑白情况进行判断,我想出了一个好方法。行列同奇同偶,为白色,行列奇偶互异为黑色。 //象如果在黑色格子上,他永远到不了白色格子,这是性质。 #include<iostream> #include<queue> using namespace std; bool vis[64]; int dir[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};//方向数组 struct chess { int coord; int step; chess(int Coord,int Step) { coord = Coord; step = Step; } }; bool legal(int x,int y)//判断点的合法 { if(x < 0 || x > 8 || y < 0 || y > 8) return false; return true; } int king(int st,int ed)//宽搜 { int x1,y1,x2,y2; memset(vis,0,sizeof(vis)); x1 = st / 8; y1 = st % 8; queue<chess> q; q.push(chess(st,0)); while(!q.empty()) { if(q.front().coord == ed) return q.front().step; int tx = q.front().coord / 8; int ty = q.front().coord % 8; int step = q.front().step; q.pop(); for(int i = 0;i < 7;++i) { x2 = tx + dir[i][0]; y2 = ty + dir[i][1]; if(!vis[x2*8+y2] && legal(x2,y2)) { vis[x2*8+y2] = 1; q.push(chess(x2*8+y2,step+1)); } } } } int queen(int st,int ed) { int x1,y1,x2,y2; x1 = st / 8; y1 = st % 8; x2 = ed / 8; y2 = ed % 8; if(x1 == x2 || y1 == y2) return 1; else if(abs(x1-x2) == abs(y1-y2)) return 1; else return 2; } int rook(int st,int ed) { int x1,y1,x2,y2; x1 = st / 8; y1 = st % 8; x2 = ed / 8; y2 = ed % 8; if(x1 == x2 || y1 == y2) return 1; else return 2; } int bishop(int st,int ed) { int x1,y1,x2,y2,color1,color2; x1 = st / 8; y1 = st % 8; x2 = ed / 8; y2 = ed % 8; if(abs(x1-x2) == abs(y1-y2)) return 1; if(x1 % 2 == y1 % 2) color1 = 1; else color1 = 0; if(x2 % 2 != y2 % 2) color2 = 0; else color2 = 1; if(color1 != color2) return -1; else return 2; } int main() { //freopen("in.txt","r",stdin); int T; int st,ed; char s1[3],s2[3]; scanf("%d",&T); while(T--) { scanf("%s%s",s1,s2); st = abs(s1[0] - 'h') + (s1[1] - '0') * 8; ed = abs(s2[0] - 'h') + (s2[1] - '0') * 8; if(st == ed)//唉,忽略了起点和中点一样的情况,贡献1WA { printf("0 0 0 0/n"); continue; } printf("%d ",king(st,ed)); printf("%d ",queen(st,ed)); printf("%d ",rook(st,ed)); int B = bishop(st,ed); if(B == -1) printf("Inf/n"); else printf("%d/n",B); } return 0; }