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

An explorer gets lost in this grid. His position now is (,), 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=), indicating the number of testcases. 

For each testcase, the first line contains two integers n and m (≤n,m≤). The i-th line of the next n lines contains one  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  unless the answer itself is  (in this case, print  instead).
 
Sample Input
 


Sample Output

Author
XJZX
Source
 

1、如果mp[0][0]==0的话,先bfs一次,将前导0去掉。bfs得到了wx,wy

2、然后就是找最小路径了。枚举步数for(int i=wx+wy;i<n+m-2;i++),在这个步数的基础上枚举所有可能的(x,y)x+y==step,如果遇到0则取0,一直找到(n-1,m-1)

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stdlib.h>
using namespace std;
#define N 1006
int n,m;
int mp[N][N];
int vis[N][N];
struct Node{
int x,y;
}st;
int dirx[]={,,-,};
int diry[]={,,,-};
int wx,wy;
void bfs(){
queue<Node>q;
q.push(st);
Node t1,t2;
while(!q.empty()){
t1=q.front();
q.pop();
for(int i=;i<;i++){
t2.x=t1.x+dirx[i];
t2.y=t1.y+diry[i];
if(vis[t2.x][t2.y]) continue;
if(t2.x< || t2.x>=n || t2.y< || t2.y>=m) continue;
vis[t2.x][t2.y]=;
if(mp[t2.x][t2.y]==){
q.push(t2);
}
if(wx+wy<t2.x+t2.y){
wx=t2.x;
wy=t2.y;
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
char s[];
for(int i=;i<n;i++){
scanf("%s",s);
for(int j=;j<m;j++){
mp[i][j]=s[j]-'';
}
}
st.x=;
st.y=;
memset(vis,,sizeof(vis));
vis[][]=;
wx=;
wy=;
if(mp[][]==){
bfs();
}
if(mp[wx][wy]==){
printf("0\n");
continue;
}
printf("");
int nowflag=;
for(int i=wx+wy;i<n+m-;i++){
int flag=;
int step=i;
for(int j=;j<=step;j++){
int x=j;
int y=i-j;
if(x< || x>=n || y< || y>=m) continue;
if(nowflag && mp[x][y]) continue;
if(!vis[x][y]) continue; for(int k=;k<;k++){
int sx=x+dirx[k];
int sy=y+diry[k];
if(sx< || sx>=n || sy< || sy>=m) continue;
vis[sx][sy]=;
if(mp[sx][sy]==){
flag=;
}
} }
nowflag=flag;
if(flag){
printf("");
}
else{
printf("");
}
}
printf("\n");
}
return ;
}

hdu 5335 Walk Out(bfs+寻找路径)的更多相关文章

  1. HDU 5335 Walk Out BFS 比较坑

    H - H Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status ...

  2. hdu 5335 Walk Out(bfs+斜行递推) 2015 Multi-University Training Contest 4

    题意—— 一个n*m的地图,从左上角走到右下角. 这个地图是一个01串,要求我们行走的路径形成的01串最小. 注意,串中最左端的0全部可以忽略,除非是一个0串,此时输出0. 例: 3 3 001 11 ...

  3. HDU 5335 Walk Out (BFS,技巧)

    题意:有一个n*m的矩阵,每个格子中有一个数字,或为0,或为1.有个人要从(1,1)到达(n,m),要求所走过的格子中的数字按先后顺序串起来后,用二进制的判断大小方法,让这个数字最小.前缀0不需要输出 ...

  4. hdu 5335 Walk Out (搜索)

    题目链接: hdu 5335 Walk Out 题目描述: 有一个n*m由0 or 1组成的矩形,探险家要从(1,1)走到(n, m),可以向上下左右四个方向走,但是探险家就是不走寻常路,他想让他所走 ...

  5. hdu 5335 Walk Out (2015 Multi-University Training Contest 4)

    Walk Out                                                                         Time Limit: 2000/10 ...

  6. hdu 5335 Walk Out 搜索+贪心

    Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S ...

  7. HDU 5335 Walk Out

    题意:在一个只有0和1的矩阵里,从左上角走到右下角, 每次可以向四个方向走,每个路径都是一个二进制数,求所有路径中最小的二进制数. 解法:先bfs求从起点能走到离终点最近的0,那么从这个点起只向下或向 ...

  8. HDU 5335——Walk Out——————【贪心】

    Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. HDU 5335 Walk Out(多校)

    Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

随机推荐

  1. [转]myeclipse 生成JAR包并引入第三方包

    myeclipse 生成JAR包并引入第三方包 我用的是myeclipse8.0 首先用myeclipse生成JAR 一.生成JAR包 1.点选项目右键—>Export 2.Java—>J ...

  2. Oracle CheckPoint进程

    在实例经过分配内存结构,加载控制文件后,然后要打开数据库的时候,需要做到控制文件,数据文件,联机重做日志保持相互状态一致性,数据库才可以打开.当数据库发生实例不正常关闭时(比如系统掉电或者Shutdo ...

  3. vs2015升级后台mvc视图编辑器默认不是razor视图引擎问题

    1.问题的原因 vs2013中创建的mvc4.0应用默认使用的razor2.0版本 在vs2015编辑器中默认使用的razor视图引擎是3.0版本 解决方案: 第一步:升级mvc应用的版本为mvc5. ...

  4. win7 安装vs2010报错 Error code -939523550 for this component is not recognizedHi

    When i try to install VS2010, Its not installing. I'm getting an error.  It just try to install the ...

  5. 一致性哈希与java实现

    一致性哈希算法是分布式系统中常用的算法.比如,一个分布式的存储系统,要将数据存储到具体的节点上,如果采用普通的hash方法,将数据映射到具体的节点上,如key%N,key是数据的key,N是机器节点数 ...

  6. .net简单页面后台绑定下拉框,按钮,分页 后台cs文件

    二.cs文件 using System;using System.Collections.Generic;using System.Web.UI;using System.Web.UI.WebCont ...

  7. 技巧集:nginx作代理时,查看请求被转发到哪台服务器

    使用Nginx代理多台服务器实行负载的时候,如何查看某一个请求被转发到哪台服务器上呢? upstream demo { server 127.0.0.1:8781; server 127.0.0.1: ...

  8. hdu Big Number 求一个数的位数

    Problem Description In many applications very large integers numbers are required. Some of these app ...

  9. 宏定义中使用do{}while(0)的好处 (转载)

    宏定义中使用do{}while(0)的好处   #define MACRO_NAME(para) do{macro content}while(0)   的格式,总结了以下几个原因:   1,空的宏定 ...

  10. Render和template?

    Template是一个模板. render = web.template.render('templates/') 这会告诉web.py到你的模板目录中去查找模板.然后把 index.GET改成: 告 ...