ZCMU-1342-Two Semiknights Meet
2017-01-12 13:05
381 查看
1342: Two Semiknights Meet
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 56 Solved: 17
[Submit][Status][Web
Board]
Description
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 squaresforward 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 matri
d517
x 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 Input
2........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Sample Output
YESNO
【解析】
本题就是叫你去判断两个人能不能见面,这两个人分别用K来表示,一个人在走的同时另一个人也在走,他们的走法是田字走法,斜着走问你他们两能不能到达同一个地点。这个时候我们总会有点感觉斜着走两格相当于x轴走了两个y轴走了两格。所以如果他们的横坐标和纵坐标都是4的倍数那肯定是可以见得到的,否则肯定是不可以的。有可能会有人奇怪为什么我输入字符又用了C++的输入,那是因为C++输入字符不会读入换行符类似的题目详见我另一篇文章http://blog.csdn.net/ZCMUCZX/article/details/53997118?locationNum=1&fps=1
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<cmath> using namespace std; int main() { int t,i,j,x1,y1,x2,y2,flag,p,q; char c; scanf("%d",&t); while(t--) { flag=0; for(i=0;i<8;i++) { for(j=0;j<8;j++) { cin>>c; if(c=='K'&&flag==0) { flag=1; x1=i; y1=j; } else if(c=='K'&&flag==1) { x2=i; y2=j; } } } p=fabs(x1-x2); q=fabs(y1-y2); if(p%4==0&&q%4==0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
相关文章推荐
- 图解Sysprep封装系统
- LVS+Keepalive
- photoshop-反相&调整颜色
- 互联网公司校招Java面试题总结及答案——网易
- ubuntu gcc编译时对’xxxx’未定义的引用问题
- 使用Policy文件来设置Java的安全策略
- Kafka consumer处理大消息数据问题
- Tesseract-OCR引擎安装
- 关于数据结构和反转课堂的心得体会
- 洛谷1781宇宙总统
- unity导出ios工程导入到另一个工程中
- 第二天学习记录
- openCV实现图片的时钟和中心圆形扩大效果
- Android电视下的JNI demo
- 人脸识别简史与近期进展
- sharesdk修改UI界面
- system
- Spring中使用两种Aware接口自定义获取bean
- 常用ARM指令集及汇编_破解
- 【Qt】槽函数中获取发出信号的对象