A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
2 ........ ........ ......#. K..##..# .......# ...##..# ......#. K....... ........ ........ ..#..... ..#..#.. ..####.. ...##... ........ ....K#K#
YES NO
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
题目链接:http://codeforces.com/contest/362/problem/A
题目的意思是8*8的棋盘上有两个K,格子有好有坏,他们走田字,好的格子和坏的格子都可以走,问能否在好的格子相遇。
很显然,如果两个人相遇一定可以在好的格子里,因为相遇后可以走到一个K的初始位置,而K的初始位置一定是好的,所以不用管格子的状态,其次,我们看横坐标,如果两个K方向一致,则横坐标的距离没有变,而如果方向相反,则横坐标的距离加四或减四,纵坐标一样,所以我们只需要判断他们两个之间的距离是否为4的倍数。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
int t;
scanf("%d",&t);
char s[100];
int x1,x2,y1,y2;
while(t--){
bool flag=false;
for(int i=0;i<8;i++){
scanf("%s",s);
for(int j=0;j<8;j++){
if(s[j]=='K'){
if(!flag){
x1=i,y1=j;
flag=true;
}
else{
x2=i,y2=j;
}
}
}
}
if((abs(x1-x2))%4==0&&(abs(y1-y2))%4==0){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return 0;
}