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

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

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

最新的火星探测机器人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 算法提高 我们的征途是星辰大海

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

查看所有标签

猜你喜欢:

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

The Joy of X

The Joy of X

Niall Mansfield / UIT Cambridge Ltd. / 2010-7-1 / USD 14.95

Aimed at those new to the system seeking an overall understanding first, and written in a clear, uncomplicated style, this reprint of the much-cited 1993 classic describes the standard windowing syste......一起来看看 《The Joy of X》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具