HDU 多校

Walk Out

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2534    Accepted Submission(s): 494


Problem Description
In an  nm maze, the right-bottom corner is the exit (position  (n,m) is the exit). In every position of this maze, there is either a  0 or a  1 written on it.

An explorer gets lost in this grid. His position now is  (1,1), and he wants to go to the exit. Since to arrive at the exit is easy for him, he wants to do something more difficult. At first, he'll write down the number on position  (1,1). Every time, he could make a move to one adjacent position (two positions are adjacent if and only if they share an edge). While walking, he will write down the number on the position he's on to the end of his number. When finished, he will get a binary number. Please determine the minimum value of this number in binary system.
 

Input
The first line of the input is a single integer  T (T=10), indicating the number of testcases. 

For each testcase, the first line contains two integers  n and  m (1n,m1000). The  i-th line of the next  n lines contains one 01 string of length  m, which represents  i-th row of the maze.
 

Output
For each testcase, print the answer in binary system. Please eliminate all the preceding  0 unless the answer itself is  0 (in this case, print  0 instead).
 

Sample Input
 
   
2 2 2 11 11 3 3 001 111 101
 

Sample Output
 
   
111 101
 

Author
XJZX
 

Source
2015 Multi-University Training Contest 4
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5338  5337  5334  5333  5332 
 

#include 
#define maxn 1000 + 10

using namespace std;
typedef pair P;

int go[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1} };
int T, n, m;
int vis[maxn][maxn];
char s[maxn][maxn];
int sx, sy;

int judge(int x, int y)
{
    if(x > 0 && y > 0 && x <= n && y <= m)
        return 1;
    return 0;
}

void bfs()
{
    queue

Q; Q.push(P(1, 1)); while(!Q.empty()) { P p = Q.front(); Q.pop(); for(int i = 0; i < 4; i++) { int x, y; x = p.first + go[i][0]; y = p.second + go[i][1]; // printf("%d--%d\n", x, y); if(!judge(x, y) || vis[x][y]) continue; vis[x][y] = 1; if(s[x][y] == '0') Q.push(P(x, y)); if(sx + sy < x + y) { sx = x; sy = y; } } } //cout<



你可能感兴趣的:(BFS)