Codeforces Round #212 (Div. 2)A
来源:互联网 发布:常州地球人软件 编辑:程序博客网 时间:2024/05/16 09:56
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#
YESNO
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).
虽然这题可以用搜索过但跟这个方法比还是麻烦多了,观察不仔细啊。又长教训了---------cf第一题是搜索的可能性很小
#include <iostream>#include<string.h>#include<stdio.h>#include<math.h>using namespace std;int main(){ int n,i,j,coun,m[2][2]; while(cin>>n) { while(n--) { coun=0; getchar(); for(i=0;i<8;i++) { for(j=0;j<8;j++) { char c=getchar(); if(c=='K') { m[coun][0]=i; m[coun++][1]=j; } } getchar(); } int g=m[0][0]-m[1][0]; int f=m[0][1]-m[1][1]; if(g%4==0&&f%4==0) cout<<"YES"; else cout<<"NO"; cout<<endl; } } return 0;}
- Codeforces Round #212 (Div. 2)A
- Codeforces Round #212 (Div. 2) A题
- Codeforces Round #212 (Div. 2) A A. Two Semiknights Meet
- Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
- Codeforces Round #212 (Div. 1) <A>
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #173 (Div. 2) A.Bit++
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- Codeforces Round #133 (Div. 2) A题
- Codeforces Round #137 (Div. 2) A题
- Codeforces Round #138 (Div. 2) A题
- 推荐八个配色网站
- JQuery Highcharts 动态图表生成方法
- C#正则截取URL网址字符串
- qeephp 的数据库查询
- c#中odp.net 4.0利用odac操作oracle数据库学习(一)
- Codeforces Round #212 (Div. 2)A
- eclipse关联android源码
- 在项目部署的时候出现表或试图不存在
- linux解压命令
- acm-C++经典程序训练---斐波那契(Fibonacci)数列
- python_修改配置文件参数
- cmd下sqlplus命令登录失败
- java版的压缩
- PL/SQL笔记1