ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CF w4d1 A. Two Semiknights Meet

2020-05-25 20:55:20  阅读:270  来源: 互联网

标签:square Semiknights Petya w4d1 semiknights ........ Meet squares meet


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.

Input

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.

Output

For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.

Examples

inputCopy
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......

........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#

outputCopy
YES
NO

Note

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.
本来想用搜索做,但做了一会做不出来,而且觉得A题应该不会用搜索,就改成算距离。
两位骑士都以 田字格 的方式走,每走一次x方向的距离变化2,两个人都走就变化4,y同理。算出两个人的距离,如果横纵坐标都能以4的倍数变化就能相遇。

#include<bits/stdc++.h>
using namespace std;
char f[10][10];
void solve()
{
	//char ch=getchar();
	int x1=0,y1=0;
	int x2=0,y2=0;
	for(int i=1;i<=8;i++){
		for(int j=1;j<=8;j++){
			cin>>f[i][j];
			if(f[i][j]=='K'){
				if(x1==0&&y1==0){
					x1=i;
					y1=j;
				}
				else {
					x2=i;
					y2=j;
				}
			}
		}
	}
	if(abs(x1-x2)%4==0&&abs(y1-y2)%4==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

int main()
{
	int t;
	cin>>t;
	while(t--)solve();
	return 0;
}
/*
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......

........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
*/

标签:square,Semiknights,Petya,w4d1,semiknights,........,Meet,squares,meet
来源: https://www.cnblogs.com/LiangYC1021/p/12960745.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有