HDU 4634 Swipe Bo (2013多校4 1003 搜索)
Swipe Bo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 455 Accepted Submission(s): 111
The main character of this game is a square blue tofu called Bo. We can swipe up / down / left / right to move Bo up / down / left / right. Bo always moves in a straight line and nothing can stop it except a wall. You need to help Bo find the way out.
The picture A shows that we needs three steps to swipe Bo to the exit (swipe up, swipe left, swipe down). In a similar way, we need only two steps to make Bo disappear from the world (swipe left, swipe up)!

Look at the picture B. The exit is locked, so we have to swipe Bo to get all the keys to unlock the exit. When Bo get all the keys, the exit will unlock automatically .The exit is considered inexistent if locked. And you may notice that there are some turning signs, Bo will make a turn as soon as it meets a

turning signs. For example, if we swipe Bo up, it will go along the purple line.
Now, your task is to write a program to calculate the minimum number of moves needed for us to swipe Bo to the exit.
The first line of each test case contains two integers N and M (1≤N, M≤200), which denote the sizes of the map. The next N lines give the map’s layout, with each line containing M characters. A character is one of the following: '#': represents the wall; 'S' represents the start point of the Bo; 'E' represents the exit; '.' represents an empty block; ‘K’ represents the key, and there are no more than 7 keys in the map; 'L','U','D','R' represents the turning sign with the direction of left, up, down, right.
######
#....#
.E...#
..S.##
.#####
5 6
######
#....#
.....#
SEK.##
.#####
5 6
######
#....#
....K#
SEK.##
.#####
5 6
######
#....#
D...E#
S...L#
.#####
2
7
-1
我是暴力搜索搞的,调试了一下竟然AC了。
注意判重。
走的过程中也要去判重。
有好几个细节
- /*
- * Author:kuangbin
- * 1003.cpp
- */
- #include <stdio.h>
- #include <algorithm>
- #include <string.h>
- #include <iostream>
- #include <map>
- #include <vector>
- #include <queue>
- #include <set>
- #include <string>
- #include <math.h>
- using namespace std;
- char g[][];
- int sx,sy,ex,ey;
- int n,m;
- int keynum;
- int key_s[][];
- int move[][] = {{,},{,-},{,},{-,}};
- struct Node
- {
- int key;//钥匙的状态
- int num;//移动数
- int x,y;
- };
- queue<Node>q;
- bool used[][][<<];
- bool used2[][][<<][];
- int bfs()
- {
- while(!q.empty())q.pop();
- Node tmp,now;
- tmp.key = ;
- tmp.num = ;
- tmp.x = sx;
- tmp.y = sy;
- q.push(tmp);
- memset(used,false,sizeof(used));
- memset(used2,false,sizeof(used2));
- used[sx][sy][] = true;
- while(!q.empty())
- {
- tmp = q.front();
- q.pop();
- for(int i = ;i < ;i++)
- {
- int mx = move[i][];
- int my = move[i][];
- int x = tmp.x;
- int y = tmp.y;
- int ss = tmp.key;
- while()
- {
- if(g[x][y] =='L')
- {
- mx = ; my = -;
- }
- if(g[x][y] == 'U')
- {
- mx = -;my = ;
- }
- if(g[x][y] == 'D')
- {
- mx = ;my = ;
- }
- if(g[x][y] == 'R')
- {
- mx = ; my = ;
- }
- int dir;
- if(mx==-&&my==)dir=;
- else if(mx==&&my==)dir=;
- else if(mx==&&my==)dir=;
- else if(mx==&&my==-)dir=;
- if(used2[x][y][ss][dir])break;
- used2[x][y][ss][dir] = true;
- x += mx;
- y += my;
- if(x < || y < || x >= n || y >= m)break;
- if(g[x][y] =='#')break;
- if( x == ex && y== ey && ss ==((<<keynum)-) )
- return tmp.num+;
- if(g[x][y] =='L')
- {
- mx = ; my = -;
- }
- if(g[x][y] == 'U')
- {
- mx = -;my = ;
- }
- if(g[x][y] == 'D')
- {
- mx = ;my = ;
- }
- if(g[x][y] == 'R')
- {
- mx = ; my = ;
- }
- if(g[x][y] == 'K')
- ss |= key_s[x][y];
- if(x+mx >= && x+mx < n && y+my>= && y+my < m && g[x+mx][y+my]=='#')
- {
- if(used[x][y][ss])break;
- now.x = x;now.y = y;
- now.key = ss;
- now.num = tmp.num + ;
- q.push(now);
- used[x][y][ss] = true;
- break;
- }
- }
- }
- }
- return -;
- }
- int main()
- {
- //freopen("1003.in","r",stdin);
- // freopen("out.txt","w",stdout);
- while(scanf("%d%d",&n,&m)==)
- {
- keynum = ;
- for(int i = ;i < n;i++)
- {
- scanf("%s",g[i]);
- for(int j = ;j < m;j++)
- {
- if(g[i][j] == 'S')
- {
- sx = i;sy = j;
- }
- if(g[i][j] == 'E')
- {
- ex = i;ey = j;
- }
- if(g[i][j] == 'K')
- {
- key_s[i][j] = (<<keynum);
- keynum++;
- }
- }
- }
- printf("%d\n",bfs());
- }
- return ;
- }
HDU 4634 Swipe Bo (2013多校4 1003 搜索)的更多相关文章
- HDU 4678 Mine (2013多校8 1003题 博弈)
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- HDU 4634 Swipe Bo 状态压缩+BFS最短路
将起始点.终点和钥匙统一编号,预处理: 1.起始点到所有钥匙+终点的最短路 2.所有钥匙之间两两的最短路 3.所有钥匙到终点的最短路 将起始点和所有钥匙四方向出发设为起点BFS一遍,求出它到任意点任意 ...
- hdu 4634 Swipe Bo 搜索
典型的bfs模拟 (广度优先搜索) ,不过有好多细节要注意,比如图中如果是 R# 走到这个R的话就无限往右走了,这样就挂了~肯定到不了出口.还有一种容易造成死循环的,比如 #E## DLLL D. ...
- hdu 4634 Swipe Bo bfs+状态压缩
题目链接 状态压缩记录当前拿到了哪些钥匙, 然后暴力搜索. 搞了好几个小时, 一开始也不知道哪里错了, 最后A了也不知道一开始哪里有问题. #include <iostream> #inc ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
- HDU 4704 Sum (2013多校10,1009题)
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- HDU 4699 Editor (2013多校10,1004题)
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 4696 Answers (2013多校10,1001题 )
Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- HDU 4690 EBCDIC (2013多校 1005题 胡搞题)
EBCDIC Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Su ...
随机推荐
- MediaWiki安装配置(Linux)【转】
转自:http://blog.csdn.net/gao36951/article/details/43965527 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 1Media ...
- Bit banging
Bit banging Bit banging is a technique for serial communications using software instead of dedicated ...
- notifier chain — 内核通知链【转】
转自:http://blog.csdn.net/g_salamander/article/details/8081724 大多数内核子系统都是相互独立的,因此某个子系统可能对其它子系统产生的事件感兴趣 ...
- http状态码+http请求方式
一.http状态码 2开头 (请求成功)表示成功处理了请求的状态代码. 200 (成功) 服务器已成功处理了请求. 通常,这表示服务器提供了请求的网页. 201 (已创建) 请求成功并且服 ...
- BZOJ1898: [Zjoi2004]Swamp 沼泽鳄鱼
1898: [Zjoi2004]Swamp 沼泽鳄鱼 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 478 Solved: 286[Submit][St ...
- idea中使用FindBugs-IDEA插件
下载 - 安装 - 重启idea即可: 项目右键或者文件右键即可看到 FindBugs 选项. 选择某个选项直接检测即可.检测结果如下图: 这里的Correctness是重点关注对象.这里面的错误往 ...
- MySQL workbench中的PK,NN,UQ,BIN,UN,ZF,AI说明
- PK: primary key (column is part of a pk) 主键- NN: not null (column is nullable) 是否为空 (非空)- UQ: uni ...
- 167. Two Sum II - Input array is sorted【Easy】【双指针-有序数组求两数之和为目标值的下标】
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- ZOJ 3498 Javabeans
脑筋急转弯. 如果是偶数个,那么第一步可以是$n/2+1$位置开始到$n$都减去$n/2$,后半段就和前半段一样了. 如果是奇数个,那么第一步可以是$(n+1)/2$位置开始到$n$都减去$(n+1) ...
- scrapy抓取拉勾网职位信息(一)——scrapy初识及lagou爬虫项目建立
本次以scrapy抓取拉勾网职位信息作为scrapy学习的一个实战演练 python版本:3.7.1 框架:scrapy(pip直接安装可能会报错,如果是vc++环境不满足,建议直接安装一个visua ...