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 ...
随机推荐
- SPOJ CIRU
SPOJ CIRU 题意 给出n个圆,求他们覆盖的面积. 解法 自适应Simpson,但需要将圆离散化一下,以保证我们查询的是一个连续的有圆的区间. 奇怪的是我没有离散化,样例都没有过,却把题给A了 ...
- 论文阅读《End-to-End Learning of Geometry and Context for Deep Stereo Regression》
端到端学习几何和背景的深度立体回归 摘要 本文提出一种新型的深度学习网络,用于从一对矫正过的立体图像回归得到其对应的视差图.我们利用问题(对象)的几何知识,形成一个使用深度特征表示的代价量(c ...
- MyEclipse报错Access restriction: The type BASE64Encoder is not accessible due to restriction on required library
错误截图: 解决办法: 1.进入Project --> Properties --> Java Build Path --> Libraries 2.remove 掉 JRE Sys ...
- ajax异步请求获取数据,实现滚动数字的效果。
BackgroundPositionAnimate.js下载 需要导入的js: <script type="text/javascript" src="js/jqu ...
- 带你认识 MySQL 之 MySQL 体系结构
序 近期一直在忙项目,各种加班加点,项目上线.渐渐的没有了学习的时间.这不,刚这几天才干抽出点时间.忙里偷闲,正在看一本数据库的书籍.相信非常多小伙伴们也都看过 - - <MySQL 技术内幕: ...
- Django连接mysql
链接文档地址:https://docs.djangoproject.com/zh-hans/2.0/intro/tutorial02/ 由于我使用的是mysql,所以设置的是mysql的: 在mysl ...
- tensorflow入门教程和底层机制简单解说——本质就是图计算,自动寻找依赖,想想spark机制就明白了
简介 本章的目的是让你了解和运行 TensorFlow! 在开始之前, 让我们先看一段使用 Python API 撰写的 TensorFlow 示例代码, 让你对将要学习的内容有初步的印象. 这段很短 ...
- POJ 1951 模拟
思路: 坑爹模拟毁我一生 给两组数据: 输入: YOURE TRAVELING THROUGH ANOTHER DIMENSION A DIMENSION NOT OF SIGHT. 输出: YR T ...
- javascript对象的深度克隆
在做项目的时候需要向对象里面添加新属性,又不想修改原对象.于是就写: var newObj = oldObj,但是新对象属性改变后就对象也会跟着改变,这是因为无论是新对象还是旧对象,指向的内存地址都是 ...
- oracle-常见的执行计划(一)
一.表访问方式 CBO基础概念中有讲到,访问表的方式有两种:全表扫描和ROWID扫描. 全表扫描的执行计划:TABLE ACCESS FULL ROWID扫描对应执行计划:TABLE ACCESS B ...