文章
10
粉丝
224
获赞
12
访问
50.7k
思路:定义结构体存放位置坐标以及方向。按照方向进行BFS,遇到边界或者陷阱或者已访问的节点,则向右转。
#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
int x, y;
char order;
node() {}
node(int x, int y, char order)
{
this->x = x;
this->y = y;
this->order = order;
}
} node;
bool judge(int x, int y, vector<vector<char>> &g, vector<vector<bool>> &vis)
{
if (vis[x][y] || g[x][y] == '*')
return false;
return true;
}
int w, h;
int main()
{
while (scanf("%d %d", &w, &h) != EOF)
{
vector<vector<char>> g(w, vector<char>(h));
queue<node> queue;
for (int i = 0; i < w; i++)
{
getchar();
for (int j = 0; j < h; j++)
{
scanf("%c", &g[i][j]);
if (g[i][j] >= 'A' && g[i][j] <= 'Z')
queue.pu...
登录后发布评论
暂无评论,来抢沙发