内容简介:输入格式输出格式
最新的火星探测机器人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-126 算法提高 扫雷
- 蓝桥杯 ADV-133 算法提高 彩票
- 蓝桥杯 ALGO-112 算法训练 暗恋
- 蓝桥杯 算法训练 审美课 java
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Blockchain Basics
Daniel Drescher / Apress / 2017-3-16 / USD 20.99
In 25 concise steps, you will learn the basics of blockchain technology. No mathematical formulas, program code, or computer science jargon are used. No previous knowledge in computer science, mathema......一起来看看 《Blockchain Basics》 这本书的介绍吧!