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 ...
随机推荐
- SQL中Group By的使用(转)
1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简 ...
- HDU 1756 Cupid's Arrow( 判断点在多边形的内外 )
链接:传送门 思路:判断每支箭是否在多边形内,计算几何点定位中水题,不清楚下面的代码能不能适用于给定点的顺序不确定( 既不是顺时针又不是逆时针 ) /************************* ...
- rest-framework框架
rest-framework框架是Django里面非常重要的框架,但提到rest-framework框架就不得不说两种请求方式,那就是CBV和FBV. FBV(function base views) ...
- poj 2954 Triangle 三角形内的整点数
poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...
- BZOJ 4026 dC Loves Number Theory (主席树+数论+欧拉函数)
题目大意:给你一个序列,求出指定区间的(l<=i<=r) mod 1000777 的值 还复习了欧拉函数以及线性筛逆元 考虑欧拉函数的的性质,(l<=i<=r),等价于 (p[ ...
- CSS隐藏overflow默认滚动条同时保留滚动效果
主要应用于移动端场景,仿移动端滚动效果.对于隐藏滚动条,众所周知overflow:hidden,但是想要的滚动效果也没了. 所以对于移动端webkit内核提供一个伪类选择器: .element::-w ...
- HDU 3073 Saving Beans
Saving Beans Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Original I ...
- 修改UTC时间
/sbin/hwclock --systohc date按照时间修正.
- [ReactVR] Start a Virtual Reality Project Using the React VR CLI
We will learn how to set up a React VR project, run the development mode with hot reloading, and tak ...
- Android px,dp,pt,sp的差别
px(像素点) mm 等Android不建议用 为什么电脑web开发能够用而Android不建议用? 由于px代表像素点个数,一般电脑分辨率都同样 不管14寸还是15寸都是1366*768而手机分辨率 ...