记录编号 |
108861 |
评测结果 |
AAAAAAAAAA |
题目名称 |
走迷宫 |
最终得分 |
100 |
用户昵称 |
752199526 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.003 s |
提交时间 |
2014-07-06 17:34:59 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cassert>
#include <algorithm>
#include <functional>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
using namespace std;
ifstream fin("maize.in");
ofstream fout("maize.out");
int m,n;//Area
int map[20][20],ans=0,bx,by,ex,ey;//Coordinate of begin and end
deque<int> X,Y,XX,YY;
void Print(void)
{
XX=X;YY=Y;
//while(YY.size()<Y.size())
//{XX.push(X.front());YY.push(Y.front());}
while(XX.size()>1)
{
fout<<"("<<XX.front()<<","<<YY.front()<<")->";
XX.pop_front();YY.pop_front();
}
fout<<"("<<XX.front()<<","<<YY.front()<<")";
XX.pop_front();YY.pop_front();
}
void DFS(int x,int y)//DFS Traverse
{
X.push_back(x);Y.push_back(y);
if(x==ex&&y==ey){Print();ans++;fout<<endl;X.pop_back();Y.pop_back();return;}
map[x][y]=0;//防止重走
if(map[x-1][y]==1)DFS(x-1,y);
if(map[x][y-1]==1)DFS(x,y-1);
if(map[x][y+1]==1)DFS(x,y+1);
if(map[x+1][y]==1)DFS(x+1,y);
X.pop_back();Y.pop_back();map[x][y]=1;
}
int main()
{
//Init
memset(map,0,sizeof(map));
fin>>m>>n;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)fin>>map[i][j];
}
fin>>bx>>by>>ex>>ey;
DFS(bx,by);
if(ans==0)fout<<-1<<endl;
return 0;
}