2015 多校联赛 ——HDU5335(Walk out)
Walk Out
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2001 Accepted Submission(s): 376
the right-bottom corner is the exit (position (n,m) is
the exit). In every position of this maze, there is either a 0 or
a 1 written
on it.
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.
indicating the number of testcases.
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.
the answer itself is 0 (in
this case, print 0 instead).
2 2
11
11
3 3
001
111
101
101
从矩阵左上角走到右下角,而且经过的数字会被以二进制的方式记录下来,求最小
思路:如果第一个位置是1,只能一直走下 或者 右,找出最小值
如果第一个位置是0,找到离右下角最近的1,然后进行上面步骤
但是当时并没有实现,超时了,感觉有点麻烦 - -,用搜索不知道怎么记录值,而且容易超
标码中的用for循环求解,感觉好机智(⊙o⊙)…,找到最近的位置 x + y,找出这些中最小的值输出,再讲它们进行标记。
P:每次离右下角i + j的点是那些固定的,在这些固定的周围继续找。
必须扩充栈用C++,否则爆掉。 自己测试时就说怎么一直有问题 TAT
#include <cstdio>
#include <algorithm>
#include <cstring>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std; int T, n, m,tot;
char S[1100][1100];
bool used[1100][1100];
char ch = '0';
char ch1 = '1'; void bfs(int x,int y)
{
if(used[x][y])
return ;
used[x][y] = true; if(S[x][y] == ch1)
return; if (x>1) bfs(x-1,y);
if (x<n) bfs(x+1,y);
if (y>1) bfs(x,y-1);
if (y<m) bfs(x,y+1);
} int main()
{
//freopen("9.txt", "r", stdin); scanf("%d",&T);
while (T--)
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", S[i] + 1);
for (int i = 0; i <= n + 1; i++) //预处理
S[i][0] = '2', S[i][m + 1] = '2';
for (int i = 0; i <= m + 1; i++)
S[0][i] = '2', S[n + 1][i] = '2';
memset(used,false,sizeof(used));
tot = 0;
bfs(1,1); if(used[n][m] && S[n][m] == ch)
{
printf("0\n");//全是0
continue;
} for(int i= 1; i <= n; i++)
for(int j = 1; j <= m; j++)
if(used[i][j])
tot = max(tot,i+j); printf("1");
for (int i = tot; i < n + m; i++)
{
char mi = '1';
for (int j = 1; j <= n; j++)
if (1 <= i - j && i - j <= m && used[j][i - j])
{
mi = min(mi, S[j + 1][i - j]);
mi = min(mi, S[j][i - j + 1]);
}
printf("%c", mi);
for (int j = 1; j <= n; j++)
if (1 <= i - j && i - j <= m && used[j][i - j])
{
if (S[j + 1][i - j] == mi) used[j + 1][i - j] = true;
if (S[j][i - j + 1] == mi) used[j][i - j + 1] = true;
}
}
printf("\n");
} return 0;
}
2015 多校联赛 ——HDU5335(Walk out)的更多相关文章
- 2015 多校联赛 ——HDU5402(模拟)
For each test case, in the first line, you should print the maximum sum. In the next line you should ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 2015 多校联赛 ——HDU5301(技巧)
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...
随机推荐
- django获取ip与数据重复性判定
获取ip if request.META.has_key('HTTP_X_FORWARDED_FOR'): ip_c = request.META['HTTP_X_FORWARDED_FOR'] el ...
- Storm概念讲解和工作原理介绍
Strom的结构 Storm与传统关系型数据库 传统关系型数据库是先存后计算,而storm则是先算后存,甚至不存 传统关系型数据库很难部署实时计算,只能部署定时任务统计分析窗口数据 ...
- raid5 阵列硬盘离线数据恢复成功案例
数据恢复故障描述: 某研究院 DELL 磁盘阵列崩溃,内置15块1TB硬盘搭建的RAID5阵列.一开始有一块硬盘离线,在更换新硬盘进行同步的过程中,第二块磁盘指示灯报警,同步失败,阵列无法正常工作. ...
- 故障公告:IIS应用程序池停止工作造成博客站点无法访问
非常抱歉,今天凌晨博客站点负载均衡中所有3台服务器的IIS应用程序池突然停止工作,造成 1:20-7:45 左右博客站点无法正常访问,由此给您带来很大的麻烦,请您谅解. 服务器操作系统是 Window ...
- 深入理解java的static关键字
static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面试官喜欢在面试时问到的知识点之一.下面就先讲述一下static关键字的用法和平常容易误解的地方,最后列 ...
- 阿里云CentOS部署小笔记
快毕业了,我用近两周的时间完成了一个nodeJs+Vue-Cli+Mysql的毕业设计,到了部署的时候了. 然而,博主使用Linux的经验有限得很,所以只能自己慢慢地填坑了. 一.准备工作 1)阿里云 ...
- 一次“峰回路转”的troubleshooting经历
某天,用户现场人员找到我,说应用的某个功能一点就报错,在数据库上直接跑功能对应的SQL也报错,SQL大致如下: 后来向他们要了alert.log和trace files,通过分析,确定为用户数据库版本 ...
- Python内置函数(41)——id
英文文档: id(object) Return the "identity" of an object. This is an integer which is guarantee ...
- Python内置函数(25)——frozenset
英文文档: class frozenset([iterable]) Return a new frozenset object, optionally with elements taken from ...
- 非PE病毒介绍
1.宏病毒 1.1 介绍 本文中的宏特制office系列办公软件中的宏,Microsoft Office中对宏的定义为"宏就是能够组织在一起的,可以作为一个独立命令来执行的一系列Word 命 ...