改了一下,省掉了win数组,但还是爆了
```cpp
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;
struct node
{
int x, y, step;
};
int n, m_, x, y, xx, yy;
char m[16385][16385];
int see[8][2] = {{0, 1}, {0, -1}, {1, 0}, {1, 1}, {1, -1}, {-1, 0}, {-1, 1}, {-1, -1}};
int move[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void get_(int x, int y, int k)
{
if (x <= 0 || y <= 0 || x > n || y > m_ || m[x][y] == 'X')
return ;
m[x][y] = 'o';
get_(x + see[k][0], y + see[k][1], k);
}
void init()
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m_; j++)
if (m[i][j] == 'o')
m[i][j] = 'O';
}
int BFS(int sx, int sy)
{
queue<node> q;
node temp;
temp.x = sx; temp.y = sy; temp.step = 0;
q.push(temp);
while (!q.empty())
{
for (int i = 0; i < 4; i++)
{
temp = q.front();
temp.x += move[i][0];
temp.y += move[i][1];
temp.step += 1;
if (m[temp.x][temp.y] == 'X') continue;
if (temp.x > n || temp.x <= 0 || temp.y > m_ || temp.y <= 0) continue;
if (m[temp.x][temp.y] == 'o') return temp.step;
q.push(temp);
}
q.pop();
}
return -1;
}
int main()
{
cin >> n >> m_;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m_; j++)
cin >> m[i][j];
while (1)
{
cin >> x >> y >> xx >> yy;
if (x == 0 && y == 0 && xx == 0 && yy == 0) break;
init();
for (int k = 0; k < 8; k++)
get_(x, y, k);
int answer = BFS(xx, yy);
if (answer != -1) cout << answer << endl;
else cout << "Poor Harry" << endl;
}
return 0;
}
```
by QiaoHongYi @ 2021-08-15 12:55:28
@[是QHY吖](/user/354972) 是队列空间爆了吧,你看看你的搜索有没有可以剪枝的地方
by 幽灵特工 @ 2021-08-15 13:13:29
@[幽灵特工](/user/332549) 谢谢
by QiaoHongYi @ 2021-08-15 13:21:35
不过按理来说队列是没有炸的,因为最多图也就只有16384个节点的
by QiaoHongYi @ 2021-08-15 13:26:06
@[是QHY吖](/user/354972)
char m[16385][16385];
by ByGones @ 2021-08-15 13:27:38
@[是QHY吖](/user/354972)
`char m[16385][16385];`
这肯定爆炸啊
by Ew_Cors @ 2021-08-15 13:28:16
额。。。。所以说要改动态的数组咯(?)
by QiaoHongYi @ 2021-08-15 13:29:13
改成vector后本地运行直接停止工作了,我vector的使用有什么问题吗QAQ
```cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <queue>
using namespace std;
struct node
{
int x, y, step;
};
int n, m_, x, y, xx, yy;
vector<string> m;
int see[8][2] = {{0, 1}, {0, -1}, {1, 0}, {1, 1}, {1, -1}, {-1, 0}, {-1, 1}, {-1, -1}};
int move[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void get_(int x, int y, int k)
{
if (x <= 0 || y <= 0 || x > n || y > m_ || m[x][y] == 'X')
return ;
m[x][y] = 'o';
get_(x + see[k][0], y + see[k][1], k);
}
void init()
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m_; j++)
if (m[i][j] == 'o')
m[i][j] = 'O';
}
int BFS(int sx, int sy)
{
queue<node> q;
node temp;
temp.x = sx; temp.y = sy; temp.step = 0;
q.push(temp);
while (!q.empty())
{
for (int i = 0; i < 4; i++)
{
temp = q.front();
temp.x += move[i][0];
temp.y += move[i][1];
temp.step += 1;
if (m[temp.x][temp.y] == 'X') continue;
if (temp.x > n || temp.x <= 0 || temp.y > m_ || temp.y <= 0) continue;
if (m[temp.x][temp.y] == 'o') return temp.step;
q.push(temp);
}
q.pop();
}
return -1;
}
int main()
{
cin >> n >> m_;
for (int i = 1; i <= n; i++)
{
char str[16385];
scanf("%s", str);
string str1 = str;
m.push_back(str1);
}
while (1)
{
cin >> x >> y >> xx >> yy;
if (x == 0 && y == 0 && xx == 0 && yy == 0) break;
init();
for (int k = 0; k < 8; k++)
get_(x, y, k);
int answer = BFS(xx, yy);
if (answer != -1) cout << answer << endl;
else cout << "Poor Harry" << endl;
}
return 0;
}
```
by QiaoHongYi @ 2021-08-15 13:36:34
@[是QHY吖](/user/354972) 极限数据应该还是会炸吧……题我没看,不过看在你一开始开那么大的数组应该是题目的边界数据,既然这样用vector也一定会炸
by 安舒阳 @ 2021-08-15 13:40:58
@[是QHY吖](/user/354972) 字符串的下标是从0开始的呢
by 幽灵特工 @ 2021-08-15 13:57:12