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


推荐阅读
  • D-War(8.4.3)CrawlinginprocessCrawlingfailedTimeLimit:3000MS    MemoryLimit:0KB  ... [详细]
  • 实验六提交版
    1.21.3part2共用体与结构体类型的区别?答:共用体与结构体的区别在于它们的表示方法不同。结构体内,结构体的各成员顺序排列存储,每个成员都有自己独立的存储位置,而共用体的情况 ... [详细]
  • Python对象特性0x01:所有Python对象都有三个特性以及属性*身份:每一个对象都有一个唯一的身份标识自己,任何一个都可以用内建函数id()来得到。*类型:决定了可以保存什 ... [详细]
  • 如何绘制直观易懂的时标网络图
    时标网络图是用活动的定位和长度表示活动历时的项目网络图。是含网络逻辑的横道图,并且是任何以工作位置和长度代表其持续时间的项目网络图。项目经理圈子在时标网络图中,以实箭线表示工作,实 ... [详细]
  • 一,深浅拷贝看拷贝列子day19-1.py假如修改的元素是一个列表,源列表也会发生变化day19-2.py为什么会这样,因为第一次修改的是一个不可变元素对应的指针发生了变化,第二次 ... [详细]
  • TP框架 事件
    原文 http:www.cnblogs.comFushichop6600241.html1.在程序运行到应用模块的时候,先进行事件的注册:对事件进行监听注册监听注册其中,获取监听权 ... [详细]
  • JS swiper轮播图完美兼容手机端
    swiper ... [详细]
  • 使用IGP和BGP的配合达到降低路由容量目的的实验与总结
    本文描述了OSPF和BGP配合来降低路由器的容量压力的实验和总结,有助于对IGP协议和BGP协议的互 ... [详细]
  • Forexamplewehavefollowingcode:$(el).hide()el.style.display'none'$(el).forEach((){ ... [详细]
  • 1:在Ubuntu中使用“apt-getinstall+app”命令可以在线安装绝大部分软件包,在高版本的Ubuntu中,apt-get可以简写为apt。2:sudo命令表示临时切 ... [详细]
  • postman使用环境变量
    变量postman提供了变量设置,有四种变量类型本地变量全局变量环境变量数据变量什么是环境变量环境变量指在不同环境,同一个变量值随着环境不同而变化,比如在测试环境时,host为:d ... [详细]
  • Windows 10 更新后VMware Workstation pro无法运行 (无需卸载原版本VM)
    Windows10-1903更新后VMwareWorkstationpro15.0.4无法运行(无需卸载原版本VM和卸载Wind ... [详细]
  • RocketdecodeSimplifyDC
    https:mp.weixin.qq.coms4uWqBRrMVG6FlnBKmw8U-w介绍SimplifyDC如何简化解码逻辑。1.使用??简化从mint和maxt中查找的逻辑 ... [详细]
  • 获取鼠标的位置/坐标
    使用javascript如何获取鼠标的位置呢?获取光标的位置?获取鼠标坐标先看效果?核心方法:****返回鼠标的坐标*@parame*@returns{{x ... [详细]
  • 题目:写一个函数返回参数二进制中1的个数方法1:我自己写的,运用‘%‘和‘‘,感觉挺简单的。intcount_one_bit(intnum){unsignedintcount0;w ... [详细]
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社区 版权所有