URAL 1197. Lonesome Knight
2015-03-21 18:38
281 查看
1197. Lonesome Knight
Time limit: 1.0 secondMemory limit: 64 MB
The statement of this problem is very simple: you are to determine how many squares of the chessboard can be attacked by a knight standing alone on the board. Recall that a knight moves two squares
forward (horizontally or vertically in any direction) and then one square sideways (perpedicularly to the first direction).
Input
The first line contains the number N of test cases, 1 ≤ N ≤ 100. Each of the following N lines contains a test: two characters. The first character is a lowercase Englishletter from 'a' to 'h' and the second character is an integer from 1 to 8; they specify the rank and file of the square at which the knight is standing.
Output
Output N lines. Each line should contain the number of the squares of the chessboard that are under attack by the knight.Sample
input | output |
---|---|
3 a1 d4 g6 | 2 8 6 |
注意边界就可以
#include<cstdio> #include<iostream> using namespace std; int knight(int m,int n) { int num=0; if(m-1>=1) { if(n-2>=1) num++; if(n+2<=8) num++; } if(m+1<=8) { if(n-2>=1) num++; if(n+2<=8) num++; } if(m+2<=8) { if(n+1<=8) num++; if(n-1>=1) num++; } if(m-2>=1) { if(n+1<=8) num++; if(n-1>=1) num++; } return num; } int main() { int n,b; char a; while(cin>>n) { for(int i=0;i<n;i++) { cin>>a>>b; printf("%d\n",knight(a-'a'+1,b)); } } return 0; }
相关文章推荐
- ural 1197. Lonesome Knight
- Ural 1197 - Lonesome Knight
- Lonesome knight[Timus OJ 1197]
- Ural 1313 - Some Words about Sport
- Ural Problem Set Volume 2: 1100-1197
- URAL 1298. Knight(DFS啊 )
- URAL1197解题报告
- URAL 1197 Lonesome Knight (判断)
- Boost.Interprocess使用手册翻译之三:一些基本解释 (Some basic explanations)
- DM&ML or some other names
- ural1057 Amount of Degrees ——数位DP
- URAL 1218 Episode N-th: The Jedi Tournament(强连通分量)(缩点)
- DFS-R: Some files are not replicating, why? - DFSR不复制带有临时属性的文件
- some 算法
- URAL1780----格雷码的应用,数论
- [求解二次剩余 数论技巧 随机化] Ural 1132 Square Root
- Sparsity and Some Basics of L1 Regularization
- Ural1005-Stone Pile
- Ural 1521. War Games 2
- Ural1613-For Fans of Statistics