#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct node
{
int x, y;
}pp[1010];
bool mp[15][15],vis[15][15];
int n, m, sx, sy, ex, ey,flag;
void DFS(int x,int y,int t)
{
if(x < 0 || x > n || y < 0 || y > m || !mp[x][y])
return;
pp[t].x = x,pp[t].y = y;
if(x == ex && y == ey)
{
flag = 1;
for(int i = 1; i <= t; i++)
{
if(i == t)
cout << '(' << pp[i].x << ',' << pp[i].y << ')' << endl;
else
cout << '(' << pp[i].x << ',' << pp[i].y << ')' << "->";
}
return;
}
if(vis[x][y] == 0)
{
vis[x][y] = 1;
DFS(x,y-1,t+1);
DFS(x-1,y,t+1);
DFS(x,y+1,t+1);
DFS(x+1,y,t+1);
vis[x][y] = 0;
}
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
cin >> mp[i][j];
}
cin >> sx >> sy;
cin >> ex >> ey;
flag = 0;
memset(vis,0,sizeof(vis));
//vis[sx][sy] = 1;
DFS(sx,sy,1);
if(flag == 0)
cout << -1 << endl;
return 0;
}
SDUT 1269 走迷宫
最新推荐文章于 2020-04-02 13:45:20 发布