
knight try
By: a guest on
May 8th, 2012 | syntax:
C++ | size: 1.45 KB | hits: 17 | expires: Never
#include <cstdio>
#include <queue>
#include <vector>
#define MAX_NODES
#define MAX_EDGES
using namespace std;
int p1 [2] = {-1, 1};
int p2 [2] = {-2, 2};
struct Horse {
int x;
int y;
int count;
Horse(int x = 0, int y = 0) : x(x), y(y) {};
};
bool visited [1000][1000];
int converter (char ch) {
return ch - 97;
}
queue <Horse> fila;
int main () {
int resposta;
char pos1 [3] ;
char pos2 [3] ;
scanf("%s %s", &pos1, &pos2);
int xi = converter(pos1[0]);
int yi = pos1[1];
int xf = converter (pos2[0]);
int yf = pos2[1];
fila.push(Horse (xi, yi));
while (!fila.empty()) {
Horse aux = fila.front();
printf("%d %d \n", aux.x, aux.y);
fila.pop();
if (visited[aux.x][aux.y]) continue;
if (aux.x == xf && aux.y == yf) {
resposta = aux.count;
break;
}
printf("teste2\n");
visited[aux.x][aux.y] = true;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
printf("teste1\n");
int xNovo = aux.x+p1[i];
int yNovo = aux.y+p2[j];
if (xNovo >= 0 && yNovo >= 0 && !visited[xNovo][yNovo]) {
Horse horse1 = Horse(xNovo, yNovo);
horse1.count += aux.count;
fila.push(horse1);
}
xNovo = aux.x+p1[i];
yNovo = aux.y+p2[j];
if (xNovo >= 0 && yNovo >= 0 && !visited[xNovo][yNovo]) {
Horse horse1 = Horse(xNovo, yNovo);
horse1.count += aux.count;
fila.push(horse1);
}
}
}
}
printf("%d", resposta);
return 0;
}