2014
01-15

# UVA 439  Knight Moves

#include <stdio.h>
#include <string.h>
int d[8][2] = {{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};

char a[3],b[3];
int num;
int x, y ,xx ,yy;
struct Q
{
int x;
int y;
int bu;
} q[10005];
int vis[15][15];
void bfs(int x, int y)
{
int rear = 1;
for (int i = 0; i < 10005; i ++)
{
q[i].bu = 99999;
}
{
for (int i = 0; i < 8; i ++)
{
if (q[head].x + d[i][0] == xx && q[head].y + d[i][1] == yy)
{
return;
}
if (q[head].x + d[i][0] >= 1 && q[head].x + d[i][0] <= 8 && q[head].y + d[i][1] >= 1 && q[head].y + d[i][1] <= 8)
{
rear ++;
}
}
}
}
int main()
{
while(scanf("%s%s", a, b) != EOF)
{
num = 0;
memset(vis, 0, sizeof(vis));
memset(q, 0, sizeof(q));
x = a[0] - 'a' + 1;
y = a[1] - '0';
xx = b[0] - 'a' + 1;
yy = b[1] - '0';
bfs(x, y);
if (x == xx && y == yy)
num = 0;
printf("To get from %s to %s takes %d knight moves.\n",a,b, num);
}
return 0;
}

1. Thanks for using the time to examine this, I truly feel strongly about it and enjoy finding out far more on this subject matter. If achievable, as you achieve knowledge

2. Thanks for using the time to examine this, I truly feel strongly about it and enjoy finding out far more on this subject matter. If achievable, as you achieve knowledge

3. 算法是程序的灵魂，算法分简单和复杂，如果不搞大数据类，程序员了解一下简单点的算法也是可以的，但是会算法的一定要会编程才行，程序员不一定要会算法，利于自己项目需要的可以简单了解。