博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Key Task
阅读量:6092 次
发布时间:2019-06-20

本文共 4088 字,大约阅读时间需要 13 分钟。

Problem Description
The Czech Technical University is rather old — you already know that it celebrates 300 years of its existence in 2007. Some of the university buildings are old as well. And the navigation in old buildings can sometimes be a little bit tricky, because of strange long corridors that fork and join at absolutely unexpected places. The result is that some first-graders have often di?culties finding the right way to their classes. Therefore, the Student Union has developed a computer game to help the students to practice their orientation skills. The goal of the game is to find the way out of a labyrinth. Your task is to write a verification software that solves this game. The labyrinth is a 2-dimensional grid of squares, each square is either free or filled with a wall. Some of the free squares may contain doors or keys. There are four di?

erent types of keys and doors: blue, yellow, red, and green. Each key can open only doors of the same color. You can move between adjacent free squares vertically or horizontally, diagonal movement is not allowed. You may not go across walls and you cannot leave the labyrinth area. If a square contains a door, you may go there only if you have stepped on a square with an appropriate key before.

 

Input
The input consists of several maps. Each map begins with a line containing two integer numbers R and C (1 ≤ R, C ≤ 100) specifying the map size. Then there are R lines each containing C characters. Each character is one of the following: [center][img]../../../data/images/C106-1004-1.JPG[/img][/center] Note that it is allowed to have [li] more than one exit, [/li] [li] no exit at all, [/li] [li] more doors and/or keys of the same color, and [/li] [li] keys without corresponding doors and vice versa. [/li] You may assume that the marker of your position (“*”) will appear exactly once in every map. There is one blank line after each map. The input is terminated by two zeros in place of the map size.
 

Output
For each map, print one line containing the sentence “Escape possible in S steps.”, where S is the smallest possible number of step to reach any of the exits. If no exit can be reached, output the string “The poor student is trapped!” instead. One step is defined as a movement between two adjacent cells. Grabbing a key or unlocking a door does not count as a step.
 

Sample Input
 
1 10 *........X 1 3 *#X 3 20 #################### #XY.gBr.*.Rb.G.GG.y# #################### 0 0
 

Sample Output
 
Escape possible in 9 steps. The poor student is trapped! Escape possible in 45 steps.
 
#include 
#include
#include
#include
using namespace std;int n, m, t;char map[100][100];bool f[1029][100][100];int dir[] = {0, 1, 0, -1, 0};int sum[100];struct node { int x, y; int temp; __int64 w;};int bfs(node x){ queue
q; q.push(x); node a, b; while (!q.empty()) { a = q.front(); q.pop(); for (int i = 0; i < 4; i++) { b = a; b.x += dir[i]; b.y += dir[i + 1]; if (b.x < 0 || b.x >= n || b.y < 0 || b.y >= m)continue; if (map[b.x][b.y] == '#')continue; // if (b.temp >= t)return -1; if (map[b.x][b.y] == 'b' || map[b.x][b.y] =='y' || map[b.x][b.y] == 'r' || map[b.x][b.y] == 'g') { b.w|=(1<<(sum[map[b.x][b.y] - 'a'])); } if (map[b.x][b.y] == 'B' || map[b.x][b.y] =='Y' || map[b.x][b.y] == 'R' || map[b.x][b.y] == 'G') { if (!(b.w & (1<
= t)return -1; return b.temp; } q.push(b); } } return -1;}int main(){ node a; sum['B'-'A']=0,sum['Y'-'A']=1,sum['R'-'A']=2,sum['G'-'A']=3; while (cin >> n >> m) { if(n==m&&m==0)break; memset(f, 0 , sizeof(f)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> map[i][j]; if (map[i][j] == '*') { a.x = i; a.y = j; a.w = 0; a.temp = 0; } } int c = bfs(a); if (c != -1) cout << "Escape possible in " << c << " steps." << endl; else cout << "The poor student is trapped!" << endl; //cout << bfs(a) << endl; } return 0;}

转载地址:http://oumwa.baihongyu.com/

你可能感兴趣的文章
report widget not working for external users
查看>>
windows phone 摄像头得到图片是旋转90°
查看>>
Linux--sed使用
查看>>
没有显示器的情况下安装和使用树莓派
查看>>
【android】使用handler更新UI
查看>>
mochiweb 源码阅读(十五)
查看>>
前端面试中的常见的算法问题
查看>>
计算机语言的基本理论
查看>>
nodejs流之行读取器例子
查看>>
批量文件重命名工具
查看>>
简单说一下UWP中的JumpList
查看>>
unity将object[]或者string对象转换成枚举enum
查看>>
以太坊系列之六: p2p模块--以太坊源码学习
查看>>
使用scikit-learn解决文本多分类问题(附python演练)
查看>>
2018 年最值得关注的 JavaScript 趋势
查看>>
什么是区块链?超级账本 Brian Behlendorf 从五个方面教你认识
查看>>
Linux中的帮助功能
查看>>
针对Android的Pegasus恶意软件版本和针对iOS的有什么不同?
查看>>
全局探色器
查看>>
Hive Export和Import介绍及操作示例
查看>>