2015 Multi-University Training Contest 4 hdu 5335 Walk Out
Walk Out
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 639 Accepted Submission(s): 114
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.
For each testcase, the first line contains two integers n and m (1≤n,m≤1000). The i-th line of the next n lines contains one 01 string of length m, which represents i-th row of the maze.
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn = ;
const int dir[][] = {,,,,-,,,-};
char mp[maxn][maxn];
int n,m,sx,sy;
queue< pii >q;
bool vis[maxn][maxn];
bool isIn(int x,int y) {
return x >= && x < n && y >= && y < m;
}
void bfs(int x,int y) {
while(!q.empty()) q.pop();
q.push(pii(x,y));
vis[x][y] = true;
while(!q.empty()) {
pii now = q.front();
q.pop();
for(int i = ; i < ; ++i) {
int nx = now.first + dir[i][];
int ny = now.second + dir[i][];
if(!isIn(nx,ny) || vis[nx][ny]) continue;
vis[nx][ny] = true;
if(mp[nx][ny] == '') q.push(pii(nx,ny));
if(sx + sy < nx + ny){
sx = nx;
sy = ny;
}
}
}
}
int main() {
int kase;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d",&n,&m);
for(int i = ; i < n; ++i) scanf("%s",mp[i]);
sx = sy = ;
memset(vis,false,sizeof vis);
vis[][] = true;
if(mp[][] == '') bfs(,);
if(mp[sx][sy] == '') puts("");
else {
bool nowflag = false;
putchar('');
for(int i = sx + sy; i < n + m - ; ++i){
bool flag = false;
for(int k = ; k <= i; ++k){
int x = k;
int y = i - k;
if(!isIn(x,y) || !vis[x][y]) continue;
if(nowflag && mp[x][y] == '') continue;
for(int j = ; j < ; ++j){
int nx = x + dir[j][];
int ny = y + dir[j][];
if(!isIn(nx,ny)) continue;
vis[nx][ny] = true;
if(mp[nx][ny] == '') flag = true;
}
}
nowflag = flag;
putchar(flag?'':'');
}
putchar('\n');
}
}
return ;
}
2015 Multi-University Training Contest 4 hdu 5335 Walk Out的更多相关文章
- hdu 5335 Walk Out (搜索)
题目链接: hdu 5335 Walk Out 题目描述: 有一个n*m由0 or 1组成的矩形,探险家要从(1,1)走到(n, m),可以向上下左右四个方向走,但是探险家就是不走寻常路,他想让他所走 ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- 趣学算法 PDF pdf 下载 陈小玉版
趣学算法pdf高清无水印版下载 最近在网上找趣学算法pdf,最后还是买了完整版,今天将本书分享出来,分享给那些和我一样在网上苦苦寻找的小可爱们,有条件的话请支持正版! 链接:https://pan.b ...
- vue 过滤器使用的传参说明
在table中,需要对obj的数据类型进行文字转换,例如后台接口返回的姓别值:1,2.其中需要页面根据字典需要把1=>男,2=>女进行转换. 以前的习惯是每一个过滤方法都写一个方法进行转换 ...
- CSS解决ul下面最后一个li的margin
1.运用css3的nth-child(3n): <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...
- angular-resource
上一篇中讲到使用$http同服务器进行通信,但是功能上比较简单,angularjs还提供了另外一个可选的服务$resource,使用它可以非常方便的同支持restful的服务单进行数据交互. 安装 n ...
- [转]收集android上开源的酷炫的交互动画和视觉效果
原文链接:http://www.open-open.com/lib/view/open1411443332703.html 描述:收集android上开源的酷炫的交互动画和视觉效果. 1.交互篇 2. ...
- 【转】工具系列:IntelliJ IDEA (Mac) 运行速度优化
转自工具系列:IntelliJ IDEA (Mac) 运行速度优化 感谢该作者解决了我使用idea debug很慢的问题 背景 IDEA 下运行程序,经常假死 5 s,作为 Mac 怎么能允许暂停 5 ...
- HDU 4333 Contest 4
一开始就想到了扩展KMP,因为只有扩展KMP才是处理后缀的.但忽然短路以为扩展KMP求的是最长公共后缀,囧....又浪费了很多时间,都是对这个算法练得不多 再看那个扩展KMP算法之后,就很确定要的就是 ...
- 使用Modernizr检测支持CSS3
使用Modernizr检测支持CSS3 如果支持某个属性,会增加一个class,名字就是该属性: 不支持,名字是no-某属性 还提供了一个全局Modernizr对象,使用如下: <script ...
- [Hyperapp] Interact with the State Object through Hyperapp Action functions
Hyperapp is an ultra lightweight (1kb), minimal, functional, JavaScript library for building UIs. It ...
- 游标和动态SQL
游标类别:静态游标(指在编译的时候,游标就与一个select语句进行了静态绑定的游标.这样的游标仅仅能作用于一个查询语句)和动态游标(就是希望我们的查询语句在执行的时候才跟游标绑定.为了使用动态游标, ...