热门标签 | 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


推荐阅读
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • QUIC协议:快速UDP互联网连接
    QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ... [详细]
  • 本文探讨了如何通过最小生成树(MST)来计算严格次小生成树。在处理过程中,需特别注意所有边权重相等的情况,以避免错误。我们首先构建最小生成树,然后枚举每条非树边,检查其是否能形成更优的次小生成树。 ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • 深入理解 Oracle 存储函数:计算员工年收入
    本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ... [详细]
  • CSS 布局:液态三栏混合宽度布局
    本文介绍了如何使用 CSS 实现液态的三栏布局,其中各栏具有不同的宽度设置。通过调整容器和内容区域的属性,可以实现灵活且响应式的网页设计。 ... [详细]
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • 本文介绍如何通过Windows批处理脚本定期检查并重启Java应用程序,确保其持续稳定运行。脚本每30分钟检查一次,并在需要时重启Java程序。同时,它会将任务结果发送到Redis。 ... [详细]
  • MySQL中枚举类型的所有可能值获取方法
    本文介绍了一种在MySQL数据库中查询枚举(ENUM)类型字段所有可能取值的方法,帮助开发者更好地理解和利用这一数据类型。 ... [详细]
  • 2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ... [详细]
  • 国内BI工具迎战国际巨头Tableau,稳步崛起
    尽管商业智能(BI)工具在中国的普及程度尚不及国际市场,但近年来,随着本土企业的持续创新和市场推广,国内主流BI工具正逐渐崭露头角。面对国际品牌如Tableau的强大竞争,国内BI工具通过不断优化产品和技术,赢得了越来越多用户的认可。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文介绍如何在 Xcode 中使用快捷键和菜单命令对多行代码进行缩进,包括右缩进和左缩进的具体操作方法。 ... [详细]
  • 理解存储器的层次结构有助于程序员优化程序性能,通过合理安排数据在不同层级的存储位置,提升CPU的数据访问速度。本文详细探讨了静态随机访问存储器(SRAM)和动态随机访问存储器(DRAM)的工作原理及其应用场景,并介绍了存储器模块中的数据存取过程及局部性原理。 ... [详细]
  • 几何画板展示电场线与等势面的交互关系
    几何画板是一款功能强大的物理教学软件,具备丰富的绘图和度量工具。它不仅能够模拟物理实验过程,还能通过定量分析揭示物理现象背后的规律,尤其适用于难以在实际实验中展示的内容。本文将介绍如何使用几何画板演示电场线与等势面之间的关系。 ... [详细]
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社区 版权所有