poj 1657 国际象棋棋盘上的距离
2014-10-01 20:51
375 查看
题意:给定国际象棋上的一个起点和一个终点,问王、后、车、象分别最少走多少步能从起点到终点。
思路:细心就可以。
思路:细心就可以。
#include <stdio.h> #include <math.h> #define max(a,b) ((a)>(b)?(a):(b)) int a,b,c,d,T; int test1(){ if(a==c || b==d) return 1; return 0; } int test2(){ if(a+b == c+d || b-a == d-c) return 1; return 0; } int main(){ freopen("a.txt","r",stdin); scanf("%d\n",&T); while(T--){ char c1,c2,ch; scanf("%c%d%c%c%d\n",&c1,&b,&ch,&c2,&d); a = c1-'a'+1; c = c2-'a'+1; if(a==c && b==d){ printf("0 0 0 0\n"); continue; } printf("%d ",max(abs(a-c),abs(b-d)));//王就是横纵坐标差的大者 if(test1())//如果起终点在横线或者直线上,那么王、后都可以直接到 printf("1 1 "); else{ if(test2())//在斜线上 printf("1 2 "); else printf("2 2 "); } //判断象 if(test2())//斜线上当然能够一步到 printf("1\n"); else if((a+b)%2 == (c+d)%2)//如果背景颜色相同,必能2步到 printf("2\n"); else printf("Inf\n"); } return 0; }
相关文章推荐
- 棋盘距离 1657 poj
- poj 1657 棋盘上的距离
- 棋盘上的距离 POJ —1657
- POJ_1657:棋盘上的距离
- poj_1657 棋盘上的距离
- POJ 1657求国际象棋的格数
- 1657 棋盘上的距离
- 2.2例题--棋盘上的距离--1657
- 2.2 1657:棋盘上的距离
- POJ1321 棋盘问题 kaungbin-搜索入门-A
- (简单) POJ 1321 棋盘问题,回溯。
- 棋盘分割--POJ 1191
- poj 1321 棋盘问题(dfs)
- POJ 1321 棋盘问题(dfs)
- poj--2236--棋盘问题(dfs)
- poj 1191棋盘分割
- POJ 1321 棋盘问题
- poj 1191 棋盘分割
- POJ 3608 求两个凸包之间的最小距离
- POJ - 1321 棋盘问题 [kuangbin带你飞]专题一 简单搜索