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 ...
随机推荐
- 四则运算2(最终版)java+jps+sqlServer
1,设计思想 (1)在java Resources里建立包和类 (2)在类里面写入方法,其中包括生成算式create()和删除算式delete()用来更新数据库中的题目 (3)Show()方法用来随机 ...
- django-1-框架介绍
<<<python虚拟环境>>> 用django框架做web开发必须要用到python虚拟环境,而且一个虚拟环境只能创建一个django项目,如果创建多个djang ...
- java数组简单逻辑代码
package cuteSnow; public class HelloWorld { // 遍历数组里面的每个数字 public static void print(int[] array){ St ...
- WinServer-授权规则
授权规则: 使用谓词可以限制网站只能使用某一种请求 来自为知笔记(Wiz)
- webstorm卡顿问题处理
webstorm卡顿问题处理 学习了:http://blog.csdn.net/qq673318522/article/details/50583831 找到WebStorm.exe.vmoption ...
- 纯粹的K12精髓 - 名师指导整理《20以内加法口诀表》
纯粹的K12精髓 - 名师指导整理<20以内加法口诀表> 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一 ...
- 葡萄城公布新版ActiveReports 9报表控件和报表server
2014年11月10日---葡萄城宣布正式公布ActiveReports9,包含了三种报表模型:RDL报表.页面报表.区域报表.对于ActiveReports中的这个最新版本号中,我们专注于提高产品的 ...
- ArcGIS Server 10.2 公布Oracle11g数据源的 Feature Service
安装好arcgis server 10.2及 Desktop 而且确保 arcgis server manager 能够正常启动执行载入服务 1.Oracle 配置 安装好Oracleserver端程 ...
- 【Bootstrap】一个PC、平板、手机同一时候使用并且美观的登陆页面
Bootstrap如同前台框架,它已经布置好不少的CSS.前端开发的使用须要则直接调用就可以.其站点的网址就是http://www.bootcss.com.使用Bootstrap能降低前端开发时候在C ...
- JavaScript原型链:prototype与__proto__
title: 'JavaScript原型链:prototype与__proto__' toc: false date: 2018-09-04 11:16:54 主要看了这一篇,讲解的很清晰,最主要的一 ...