蓝桥杯 ADV-201 算法提高 我们的征途是星辰大海

栏目: 编程工具 · 发布时间: 7年前

内容简介:输入格式输出格式

最新的火星探测机器人curiosity被困在了一个二维迷宫里,迷宫由一个个方格组成。

共有四种方格:

‘.’ 代表空地,curiosity可以穿过它

‘#’ 代表障碍物,不可穿越,不可停留

‘S’ 代表curiosity的起始位置

‘T’ 代表curiosity的目的地

输入格式

第一行是一个整数T,代表有几个测试样例

输出格式

对于每个询问输出单独的一行:

“I get there!”:执行给出的命令后curiosity最终到达了终点。

“I have no idea!”:执行给出的命令后curiosity未能到达终点。

“I am dizzy!”:curiosity在执行命令的过程中撞到了障碍物。

“I am out!”:代表curiosity在执行命令的过程中走出了迷宫的边界。

Sample Input

2

2

S.

#T

2

RD

DR

3

S.#

.#.

.T#

3

RL

DDD

DDRR

Sample Output

I get there!

I am dizzy!

I have no idea!

I am out!

I get there!

#include <iostream>
#include <cstring>
using namespace std;
int main() {
    int k;
    cin >> k;
    while (k--) {
        int n, m, sx, sy, ex, ey;
        char cc[100][100];
        memset(cc, '0', sizeof(cc));
        cin >> n;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                scanf(" %c ", &cc[i][j]);
                if (cc[i][j] == 'S') {
                    sx = i;
                    sy = j;
                }
                if (cc[i][j] == 'T') {
                    ex = i;
                    ey = j;
                }
            }
        }
        cin >> m;
        while (m--) {
            int nowx = sx, nowy = sy, flag = 0;
            string s;
            cin >> s;
            for (int i = 0; i < s.length(); i++) {
                if (s[i] == 'R') nowy++;
                if (s[i] == 'L') nowy--;
                if (s[i] == 'U') nowx--;
                if (s[i] == 'D') nowx++;
                if (cc[nowx][nowy] == '#') {
                    flag = 1;
                    cout << "I am dizzy!\n";
                    break;
                } else if (cc[nowx][nowy] == '0') {
                    flag = 1;
                    cout << "I am out!\n";
                    break;
                } else if (cc[nowx][nowy] == 'T') {
                    flag = 1;
                    cout << "I get there!\n";
                    break;
                }
            }
            if (flag == 0)
                cout << "I have no idea!\n";
        }
    }
    return 0;
}
❤❤点击这里 -> 订阅PAT、蓝桥杯、GPLT天梯赛、LeetCode题解离线版❤❤ 蓝桥杯 ADV-201 算法提高 我们的征途是星辰大海

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms for Image Processing and Computer Vision

Algorithms for Image Processing and Computer Vision

Parker, J. R. / 2010-12 / 687.00元

A cookbook of algorithms for common image processing applications Thanks to advances in computer hardware and software, algorithms have been developed that support sophisticated image processing with......一起来看看 《Algorithms for Image Processing and Computer Vision》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

MD5 加密
MD5 加密

MD5 加密工具