#include<stdio.h>
#include<string.h>
#include<stack>
#include<algorithm>
using namespace std;
stack<int>s1,s2;
int a[6][6],b[6][6];
int di[4][2]={1,0,0,-1,-1,0,0,1};
int judge(int x,int y)
{
    return x>=0&&x<5&&y>=0&&y<5&&a[x][y]==0&&!b[x][y];
}
int dfs(int x,int y)
{
    if(x==4&&y==4)
    {
        s1.push(x);s2.push(y);
                return 1;
    }
    b[x][y]=1;
    if(judge(x+1,y)&&dfs(x+1,y)||judge(x,y-1)&&dfs(x,y-1)||judge(x,y+1)&&dfs(x,y+1)||judge(x-1,y)&&dfs(x-1,y))
    {
        s1.push(x);s2.push(y);
        return 1;
    }
    else return 0;
    return 0;
}
void print()
{
    while(!s1.empty())
    {
        printf("(%d, %d)\n",s1.top(),s2.top());
        s1.pop();s2.pop();
    }
}


int main()
{
    int i,j;
    for(i=0;i<5;i++)
        for(j=0;j<5;j++)
        scanf("%d",&a[i][j]);
    memset(b,0,sizeof(b));
    dfs(0,0);
    print();
    return 0;
}

 

posted on 2017-03-14 09:28  benTuTuT  阅读(1788)  评论(0编辑  收藏  举报