• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #212 Div2 A

A. Two Semiknights Meet
time limit per test 1 second
memory limit per test 256 megabytes
 
其实一个公式就可以了!

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.

Sample test(s)
Input
2 
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......

........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
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.

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 #define maxn 105
 7 int a[maxn][maxn];
 8 char s[maxn][maxn];
 9 int xx[maxn];
10 int yy[maxn];
11 int main(){
12     int t, n, m;
13     scanf("%d", &t);
14     while (t--){
15         int c = 0;
16         memset(xx, 0, sizeof xx);
17         memset(yy, 0, sizeof yy);
18         for (int i = 0; i < 8; i++){
19             scanf("%s", s[i]);
20             for (int j = 0; j < 8; j++){
21                 if (s[i][j] == 'K'){
22                     xx[c] = i;
23                     yy[c++] = j;
24                 }
25             }
26         }
27         int flag = 0;
28         int x, y;
29         x = abs(xx[1] - xx[0]), y = abs(yy[1] - yy[0]);
30         if ((x + y )% 4 != 0 || x % 2 != 0 || y % 2 != 0||x==6||y==6||(x==2&&y==2)){printf("NO\n"); continue;}
31         for (int i = 0; i < 8; i++){
32             for (int j = 0; j < 8; j++){
33                 x = abs(i - xx[0]);
34                 y = abs(j - yy[0]);
35                 if ((x + y) % 4 == 0 && x % 2 == 0 && y % 2 == 0 && s[i][j] != '#'){ flag = 1; i = 10; j = 10; break; }
36             }
37         }
38         if (flag){ printf("YES\n"); }
39         else printf("NO\n");
40     }
41     return 0;
42 }
View Code
posted @ 2013-11-15 09:44  HaibaraAi  阅读(106)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3