Go to diff to previous submission
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <queue> #include <utility> using namespace std; int grid[100][100]; int r, s, m_x, m_y ,dest_x, dest_y; bool koniec; queue<pair<int,int> > fronta; void skoc(int x, int y, int from_x, int from_y) { if(x<s && y<r && x>=0 && y>=0) { if(grid[x][y]==0) { grid[x][y]=grid[from_x][from_y]+1; //printf("x = %d y = %d n = %d --- from_x=%d, from_y=%d\n", x, y, grid[x][y], from_x, from_y); fronta.push(make_pair(x,y)); if(x==m_x && y==m_y) koniec=true; } } } int main() { pair<int,int> suradnice; int x,y; while(scanf("%d%d%d%d%d%d", &r, &s, &m_y, &m_x, &dest_y, &dest_x)==6) { memset(grid, 0, sizeof(int)*100*100); koniec=false; m_x--; m_y--; dest_x--; dest_y--; grid[dest_x][dest_y]=-1; while(!fronta.empty()) fronta.pop(); //printf("fronta.push(%d,%d)\n", dest_x, dest_y); fronta.push(make_pair(dest_x,dest_y)); while(!fronta.empty()) { suradnice=fronta.front(); fronta.pop(); // printf("fronta.pop = (%d,%d)\n", suradnice.first, suradnice.second); x=suradnice.first+2; y=suradnice.second+1; skoc(x, y, suradnice.first, suradnice.second); x=suradnice.first+1; y=suradnice.second+2; skoc(x, y, suradnice.first, suradnice.second); x=suradnice.first-1; y=suradnice.second+2; skoc(x, y, suradnice.first, suradnice.second); x=suradnice.first-2; y=suradnice.second+1; skoc(x, y, suradnice.first, suradnice.second); x=suradnice.first-2; y=suradnice.second-1; skoc(x, y, suradnice.first, suradnice.second); x=suradnice.first-1; y=suradnice.second-2; skoc(x, y, suradnice.first, suradnice.second); x=suradnice.first+1; y=suradnice.second-2; skoc(x, y, suradnice.first, suradnice.second); x=suradnice.first+2; y=suradnice.second-1; skoc(x, y, suradnice.first, suradnice.second); if(koniec) break; } if(grid[m_x][m_y]==0) printf("impossible\n"); else printf("%d\n", (grid[m_x][m_y]+1)); } return 0; }
--- c4.s863.cteam072.grasshop.cpp.0.grasshop.cpp +++ c4.s993.cteam072.grasshop.cpp.0.grasshop.cpp @@ -4,4 +4,5 @@ #include <cmath> #include <queue> +#include <utility> using namespace std; @@ -19,4 +20,5 @@ { grid[x][y]=grid[from_x][from_y]+1; + //printf("x = %d y = %d n = %d --- from_x=%d, from_y=%d\n", x, y, grid[x][y], from_x, from_y); fronta.push(make_pair(x,y)); if(x==m_x && y==m_y) @@ -30,5 +32,5 @@ pair<int,int> suradnice; int x,y; - while(scanf("%d%d%d%d%d%d", &r, &s, &m_x, &m_y, &dest_x, &dest_y)==6) + while(scanf("%d%d%d%d%d%d", &r, &s, &m_y, &m_x, &dest_y, &dest_x)==6) { memset(grid, 0, sizeof(int)*100*100); @@ -37,4 +39,6 @@ dest_x--; dest_y--; grid[dest_x][dest_y]=-1; + while(!fronta.empty()) fronta.pop(); + //printf("fronta.push(%d,%d)\n", dest_x, dest_y); fronta.push(make_pair(dest_x,dest_y)); while(!fronta.empty()) @@ -42,4 +46,5 @@ suradnice=fronta.front(); fronta.pop(); + // printf("fronta.pop = (%d,%d)\n", suradnice.first, suradnice.second); x=suradnice.first+2;