POJ - 3984 迷宫问题 dfs解法

#include<stdio.h>
#include<string.h>
#include<stack>
#include<algorithm>
using namespace std;
stack<int>s1,s2;
int a[][],b[][];
int di[][]={,,,-,-,,,};
int judge(int x,int y)
{
return x>=&&x<&&y>=&&y<&&a[x][y]==&&!b[x][y];
}
int dfs(int x,int y)
{
if(x==&&y==)
{
s1.push(x);s2.push(y);
return ;
}
b[x][y]=;
if(judge(x+,y)&&dfs(x+,y)||judge(x,y-)&&dfs(x,y-)||judge(x,y+)&&dfs(x,y+)||judge(x-,y)&&dfs(x-,y))
{
s1.push(x);s2.push(y);
return ;
}
else return ;
return ;
}
void print()
{
while(!s1.empty())
{
printf("(%d, %d)\n",s1.top(),s2.top());
s1.pop();s2.pop();
}
} int main()
{
int i,j;
for(i=;i<;i++)
for(j=;j<;j++)
scanf("%d",&a[i][j]);
memset(b,,sizeof(b));
dfs(,);
print();
return ;
}
上一篇:JMeter------ _time 函数的使用(时间戳、当前时间)


下一篇:date命令使用