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. poj 3744 Scout YYF I (矩阵)

    Description YYF -p. Here is the task, given the place of each mine, please calculate the probality t ...

  2. (转)iOS7界面设计规范(12) - UI基础 - 品牌

    重要:这是针对于正在开发中的API或技术的预备文档(预发布版本).虽然该文档在技术精确度上经过了严格的审核,但并非最终版本,仅供苹果开发者计划的注册会员使用.苹果提供这份机要文档的目的,是帮助你按照文 ...

  3. 在 IIS 上创建 FTP 站点

    微软参考文档: 在 IIS 上生成 FTP 站点 主要过程: 1.控制面板 -> 程序 -> 启动或关闭Windows功能 -> 将Internet Information Serv ...

  4. 信息熵(Entropy)究竟是用来衡量什么的?

    信息熵(Entropy)究竟是用来衡量什么的? ——与Philip ZHANG商榷 思明 Philip ZHANG先生在反驳彭小明的时候,提出一个观点,他说:“ 就语言文 字来说,总体效率不是用民族主 ...

  5. LNMP、LAMP、LANMP一键安装脚本(定期更新)[转]

    这个脚本是使用shell编写,为了快速在生产环境上部署LNMP/LAMP/LANMP(Linux.Nginx/Tengine.MySQL/MariaDB/Percona.PHP),适用于CentOS/ ...

  6. Qt使用QGraphicsView实现滑动窗体效果

    QGraphicsView用来显示一个滚动视图区的QGraphicsScene内容.QGraphicsScene提供了QGraphicsItem的容器功能.通常与QGraphicsView一起使用来描 ...

  7. DotNet加密方式解析--散列加密

    没时间扯淡类,赶紧上车吧. 在现代社会中,信息安全对于每一个人都是至关重要的,例如我们的银行账户安全.支付宝和微信账户安全.以及邮箱等等,说到信息安全,那就必须得提到加密技术,至于加密的一些相关概念, ...

  8. Linq to Entities不识别方法

    db.UserValidates.Include(a => a.User).Where(uv => u.UserValidates.Contains(uv, c)).ToList(); 执 ...

  9. (转)CommandArgument用法

    1.绑定数据库中一个主键前台代码:<ItemTemplate>                        <asp:ImageButton ID="ibtnUpdate ...

  10. NSString字符串类型-学习总结

    1.字符串的创建 (1)创建常量字符串 NSString *str = @"This is a String"; //str是变量名 (2)创建空的字符串,给字符串赋值 NSStr ...