热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

KeyTask

ProblemDescriptionTheCzechTechnicalUniversityisratherold—youalreadyknowthatitcelebrate
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)
{
    queueq;
    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] == &#39;#&#39;)continue;
            // if (b.temp >= t)return -1;
            if (map[b.x][b.y] == &#39;b&#39; || map[b.x][b.y] ==&#39;y&#39; || map[b.x][b.y] == &#39;r&#39; || map[b.x][b.y] == &#39;g&#39;) {
                b.w|=(1<<(sum[map[b.x][b.y] - &#39;a&#39;]));
            }
            if (map[b.x][b.y] == &#39;B&#39; || map[b.x][b.y] ==&#39;Y&#39; || map[b.x][b.y] == &#39;R&#39; || map[b.x][b.y] == &#39;G&#39;) {
                if (!(b.w & (1<= t)return -1;
                return b.temp;
            }
            q.push(b);
        }
    }
    return -1;
}
int main()
{
    node a;
    sum[&#39;B&#39;-&#39;A&#39;]=0,sum[&#39;Y&#39;-&#39;A&#39;]=1,sum[&#39;R&#39;-&#39;A&#39;]=2,sum[&#39;G&#39;-&#39;A&#39;]=3;
    while (cin >> n >> m) {
         if(n==m&&m==0)break;
        memset(f, 0 , sizeof(f));
        for (int i = 0; i > map[i][j];
                if (map[i][j] == &#39;*&#39;) {
                    a.x = i;
                    a.y = j;
                    a.w = 0;
                    a.temp = 0;
                }
            }
        int c = bfs(a);
        if (c != -1)
            cout <<"Escape possible in " <

Key Task,,

Key Task


推荐阅读
  • Appium + Java 自动化测试中处理页面空白区域点击问题
    在进行移动应用自动化测试时,有时会遇到某些页面没有返回按钮,只能通过点击空白区域返回的情况。本文将探讨如何在Appium + Java环境中有效解决此类问题,并提供详细的解决方案。 ... [详细]
  • 探讨 HDU 1536 题目,即 S-Nim 游戏的博弈策略。通过 SG 函数分析游戏胜负的关键,并介绍如何编程实现解决方案。 ... [详细]
  • 深入解析动态代理模式:23种设计模式之三
    在设计模式中,动态代理模式是应用最为广泛的一种代理模式。它允许我们在运行时动态创建代理对象,并在调用方法时进行增强处理。本文将详细介绍动态代理的实现机制及其应用场景。 ... [详细]
  • 深入理解ExtJS:从入门到精通
    本文详细介绍了ExtJS的功能及其在大型企业前端开发中的应用。通过实例和详细的文件结构解析,帮助初学者快速掌握ExtJS的核心概念,并提供实用技巧和最佳实践。 ... [详细]
  • Python自动化测试入门:Selenium环境搭建
    本文详细介绍如何在Python环境中安装和配置Selenium,包括开发工具PyCharm的安装、Python环境的设置以及Selenium包的安装方法。此外,还提供了编写和运行第一个自动化测试脚本的步骤。 ... [详细]
  • 本文介绍了如何通过Java代码计算一个整数的位数,并展示了多个基础编程示例,包括求和、平均分计算、条件判断等。 ... [详细]
  • 本题要求在一组数中反复取出两个数相加,并将结果放回数组中,最终求出最小的总加法代价。这是一个经典的哈夫曼编码问题,利用贪心算法可以有效地解决。 ... [详细]
  • 本篇文章介绍如何将两个分别表示整数的链表进行相加,并生成一个新的链表。每个链表节点包含0到9的数值,如9-3-7和6-3相加得到1-0-0-0。通过反向处理链表、逐位相加并处理进位,最终再将结果链表反向,即可完成计算。 ... [详细]
  • ListView简单使用
    先上效果:主要实现了Listview的绑定和点击事件。项目资源结构如下:先创建一个动物类,用来装载数据:Animal类如下:packagecom.example.simplelis ... [详细]
  • 如何清除Chrome浏览器地址栏的特定历史记录
    在使用Chrome浏览器时,你可能会发现地址栏保存了大量浏览记录。有时你可能希望删除某些特定的历史记录而不影响其他数据。本文将详细介绍如何单独删除地址栏中的特定记录以及批量清除所有历史记录的方法。 ... [详细]
  • 利用Selenium与ChromeDriver实现豆瓣网页全屏截图
    本文介绍了一种使用Selenium和ChromeDriver结合Python代码,轻松实现对豆瓣网站进行完整页面截图的方法。该方法不仅简单易行,而且解决了新版Selenium不再支持PhantomJS的问题。 ... [详细]
  • 嵌入式开发环境搭建与文件传输指南
    本文详细介绍了如何为嵌入式应用开发搭建必要的软硬件环境,并提供了通过串口和网线两种方式将文件传输到开发板的具体步骤。适合Linux开发初学者参考。 ... [详细]
  • 鼠标悬停出现提示信息怎么做
    概述–提示:指启示,提起注意或给予提醒和解释。在excel中会经常用到给某个格子增加提醒信息,比如金额提示输入数值或最大长度值等等。设置方式也有多种,简单的,仅为单元格插入批注就可 ... [详细]
  • 本文探讨了C++编程中理解代码执行期间复杂度的挑战,特别是编译器在程序运行时生成额外指令以确保对象构造、内存管理、类型转换及临时对象创建的安全性。 ... [详细]
  • 本文详细介绍了如何解决 Microsoft SQL Server 中用户 'sa' 登录失败的问题。错误代码为 18470,提示该帐户已被禁用。我们将通过 Windows 身份验证方式登录,并启用 'sa' 帐户以恢复其访问权限。 ... [详细]
author-avatar
王乐668_802
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有