Because the small omission, spent half an hour of water problem
Title Description
There is a labyrinth of m*n (denoted by M-line, n column), which can walk also have not to walk, if 1 means can walk, 0 means not to go, the file read into this m*n data and start point, end Point (the starting point and end point are described by two data, respectively, the point of the line and column number). Now you have to program to find all the feasible road, the road is not to repeat the point, the time can only be up and down four directions. If a path is not feasible, output the corresponding information (with-l for no path).
Input/output format
Input format:
The first line is two number m,n (1<M,N<15), followed by the M row n column of data consisting of 1 and 0, and the last two lines are the starting and ending points.
Output format:
All feasible paths, describing a point in the form of (x, y), in addition to the start point, the other is to use "one >" to indicate the direction.
If there is not a feasible way to output-1.
Input and Output Sample input example # #:
5 61 0 0 1 0 11 1 1 1 1 10 0 1 1 1 01 1 1 1 1 01 1 1 0 1 11 15 6
Sample # # of output:
(2,1), (2,2), (2,3), (2,4), (2,5), (3,5), (3,4), (3,3)--(4,3), (4,5), (5,5), (5,6) (a), (2,1), (2,2), (2,3), (2,4), (2,5), (3,5), (3,4), (+) (4,5), (5,5), (5,6) (), (2,1), (2,2), (2,3), (2,4)-(2,5), (3,5)-(4,5), (5,5), (5,6) (2,1), (2,2), (2,3), (2,4), (3,4), (3,3), (4,3), (4,5) (5,6), (5,5), (2,1), (2,2), (2,3), (2,4), (3,4), (3,5), (4,5), (5,6) (2,1), (2,2), (2,3), (2,4), (3,4)--(4,5), (5,5), (5,6), (2,1) (2,2), (2,3), (3,3), (3,4), (2,4), (2,5), (3,5), (4,5), (5,5), (5,6) (2,1), (2,2), (2,3), (3,3), (3,4), (3,5), (4,5), (5,5), (5,6), (2,1)--(2,2) (2,3), (3,3), (3,4), (5,5), (5,6), (4,5)--(+), (2,1), (2,2) (3,3)(4,3), (3,4), (2,4), (2,5), (3,5), (4,5), (5,5), (5,6), (2,1), (2,2), (2,3), (3,3), (4,3)--(3,4), (3,5), (4,5), (5,5)--(5,6), (2,1) (2,2), (2,3), (3,3), (4,3), (4,5), (5,5)--(5,6)
The problem itself is no difficulty
1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 Const intmxn= -;9 intMP[MXN][MXN];Ten intVIS[MXN][MXN]; One intn,m; A intSx,sy,ex,ey;//always point coordinates - intwx[mxn*Ten],wy[mxn*Ten];//Path - intmx[5]={0,-1,0,0,1}, themy[5]={0,0,-1,1,0}; - BOOLflag=0; - voidPrint (intLen) { - for(intI=1; i<len;i++) printf ("(%d,%d)", Wx[i],wy[i]); +flag=1; - //printf ("(%d,%d) \ n", Wx[len],wy[len]); + return; A } at voidDfsintXintYintL) { - if(X==ex && y==ey) { - Print (L); -printf"(%d,%d) \ n", x, y); - return; - } in //order is lower left bottom right upper -wx[l]=x;wy[l]=y; tovis[x][y]=1; + for(intI=0; i<=4; i++){ - intnx=x+Mx[i]; the intny=y+My[i]; * //printf ("Test:%d%d%d\n", nx,ny,l); $ if(nx>0&& nx<=m && ny>0&& ny<=n && Mp[nx][ny] &&!Vis[nx][ny]) { Panax NotoginsengDFS (nx,ny,l+1); - } the } +vis[x][y]=0; A return; the } + intMain () { -scanf"%d%d",&m,&n); $ inti,j; $ for(i=1; i<=m;i++) - for(j=1; j<=n;j++){ -scanf"%d",&mp[i][j]); the } -scanf"%d%d",&sx,&sy);Wuyiscanf"%d%d",&ex,&ey); thewx[1]=sx;wy[1]=Sy; -vis[sx][sy]=1; Wu if(Sx==ex && Sy==ey) {printf ("-1\n") ;return 0;} -DFS (Sx,sy,1); About if(!flag) printf ("-1\n"); $ return 0; -}
Rokua P1238 Walking Maze