codeforces 362A找规律
2013-11-20 21:08
232 查看
刚开始以为是搜索白忙活了原来是个简单的找规律,以后要多想啊
此题是两马同时跳
A. Two Semiknights Meet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 and2 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
Output
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.
http://blog.csdn.net/firwaless/article/details/16342823
#include<stdio.h>
#include<math.h>
int main() {
int m,i,j,t,startx,starty,endx,endy;
char s[10][10];
scanf("%d",&t);
while(t--) {
for(i=1;i<=8;i++)
scanf("%s",s[i]+1);
m=0;
for(i=1;i<=8;i++)
for(j=1;j<=8;j++) {
if(s[i][j]=='K'&&m==0) {
m=1;
startx=i;
starty=j;
}
else
if(s[i][j]=='K') {
endx=i;
endy=j;
}
}
startx=abs(startx-endx);
endx=abs(starty-endy);
if(startx%4==0&&endx%4==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
此题是两马同时跳
A. Two Semiknights Meet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 and2 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.
http://blog.csdn.net/firwaless/article/details/16342823
#include<stdio.h>
#include<math.h>
int main() {
int m,i,j,t,startx,starty,endx,endy;
char s[10][10];
scanf("%d",&t);
while(t--) {
for(i=1;i<=8;i++)
scanf("%s",s[i]+1);
m=0;
for(i=1;i<=8;i++)
for(j=1;j<=8;j++) {
if(s[i][j]=='K'&&m==0) {
m=1;
startx=i;
starty=j;
}
else
if(s[i][j]=='K') {
endx=i;
endy=j;
}
}
startx=abs(startx-endx);
endx=abs(starty-endy);
if(startx%4==0&&endx%4==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
相关文章推荐
- C语言中关于数组、指针以及函数的一些基本知识
- 滚动数组(2)
- 存储系统文章汇总
- 隐藏音乐控件——最简单的最兼容
- USACO TRAINING 1.4.4 Arithmetic Progressions(暴力+非递归)
- knockout --- foreach -- 前端必备
- 学习笔记
- leetcode之 Palindrome Partitioning I&II
- web网站结构
- iScroll下拉加载更多例子
- hdu 3097 The Partition of A Graph uva 11396 Claw Decomposition
- leetcode之 Palindrome Partitioning I&II
- hdu2602Bone Collector (简箪01背包)
- C# 操作符重载
- 对于数据库设计者而言,在设计表属性类型时应该考虑哪些问题?
- win7电脑磁盘文件以分组方式展现解决方案
- android 分享功能,实现分享的程序与进行分享信息的代码
- 职责链模式----主界面显示
- 串的反转
- win7电脑磁盘文件以分组方式展现解决方案