#include <cstdio> #include <queue> #include <iostream> using namespace std; #define mp make_pair #define fi first #define se second #define sf scanf #define pf printf #define rep(i,a,b) for(int i=a;i<(b);++i)
bool mm[6][6]; pair<int,int> pre[5][5];
void bfs(int x, int y) { queue<pair<int, int> > qq; qq.push(mp(x, y)); while(!qq.empty()) { int inext[] = {0, 0, -1, 1}; int jnext[] = {-1, 1, 0, 0}; rep(k, 0, 4) { int icur = qq.front().fi + inext[k]; int jcur = qq.front().se + jnext[k]; if(icur < 0 || icur >4 || jcur < 0 || jcur > 4 || (icur == x && jcur == y)) continue; if(!mm[icur][jcur] && !pre[icur][jcur].first) { qq.push(mp(icur, jcur)); pre[icur][jcur] = qq.front(); } if(icur == 0 && jcur == 0) return; } qq.pop(); } }
int main() { rep(i, 0, 5) rep(j, 0, 5) cin>>mm[i][j]; bfs(4, 4); puts("(0, 0)"); pair<int, int> tmp(0, 0); while(tmp.fi != 4 || tmp.se != 4) { int i = tmp.fi; int j = tmp.se; pf("(%d, %d)\n", pre[i][j].fi, pre[i][j].se); tmp = pre[i][j]; } return 0; }
|