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 ...
随机推荐
- [中文] 以太坊(Ethereum )白皮书
以太坊(Ethereum ):下一代智能合约和去中心化应用平台 翻译|巨蟹 .少平 译者注|中文读者可以到以太坊爱好者社区(www.ethfans.org)获取最新的以太坊信息. 当中本聪在2009年 ...
- pytorch 6 build_nn_quickly 快速搭建神经网络
import torch import torch.nn.functional as F # replace following class code with an easy sequential ...
- 小学生绞尽脑汁也学不会的python(反射)
小学生绞尽脑汁也学不会的python(反射) 1. issubclass, type, isinstance issubclass 判断xxxx类是否是xxxx类的子类 type 给出xxx的数据类型 ...
- C#调用带结构体指针的C Dll的方法【转】
发现一篇文章关于C#调用DALL动态链接库的函数的,复制下来学习用.感谢作者的分析,原文传送门:https://www.cnblogs.com/ye-ming/p/8004314.html 在C#中调 ...
- SM32 USART与USB接收不定数据方法,标准库、HAL库都适用
很多时候,我们使用串口或USB接收数据时,往往不知道PC端会发多长的数据下来, 为了解决这个不定数据接收问题,在此各提供一个解决思路. 串口数据不定接收: 由于STM32单片机带IDLE中断,所以利用 ...
- kqueue演示样例
网络server通常都使用epoll进行异步IO处理,而开发人员通常使用mac,为了方便开发.我把自己的handy库移植到了mac平台上. 移植过程中,网上竟然没有搜到kqueue的使用样例.让我吃惊 ...
- atitit。企业组织与软件project的策略 战略 趋势 原则 attilax 大总结
atitit. 企业组织与软件project的策略 战略 趋势 原则 attilax 大总结 1. 战略规划,适当的过度设计 1 2. 跨平台化 1 3. 可扩展性高于一切 1 4. 界面html5化 ...
- Remove Duplicates from Sorted List II 解答(有个比較特殊的case leetcode OJ没有覆盖)
昨天被考了一道数据结构题,当时的实现比較一般.回来翻看leetcode,果然是上面的题.遂解之. accept之后翻看discuss别人的解法.发现非常多能够accept的代码都过不了我设计的一个ca ...
- mybatis和hibernate的区别【转】
第一章 Hibernate与MyBatisHibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀的 ...
- mydumper安装及安装故障汇总
mydumper是针对mysql数据库备份的一个轻量级第三方的开源工具,备份方式术语逻辑备份.它支持多线程.备份速度远高于原生态的mysqldump以及众多优异特性. 因此该工具是DBA们的不二选 ...