广搜82分求助!WA on #1 & #10
查看原帖
广搜82分求助!WA on #1 & #10
494699
卷王慢即快楼主2022/12/19 20:54
#include <bits/stdc++.h>
using namespace std;
struct node
{
	int x, y, step;
};
int n, m, sx, sy, ans = 0;
char a[101][101];
bool vis[101][101];
queue<node> q;
int work[8][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
int main()
{
	cin >> n >> m >> sx >> sy;
	for(int i = n; i >= 1; i--)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	q.push((node){sx, sy, 0});
	vis[sx][sy] = 1;
	while(!q.empty())
	{
		node u = q.front(); q.pop();
		int ux = u.x, uy = u.y, us = u.step;
		ans = max(ans, us);
		for(int i = 0; i < 8; i++)
		{
			int x = ux + work[i][0], y = uy + work[i][1];
			if(x <= 0 || x > n || y <= 0 || y > m) continue;
			if(a[x][y] == '*' || vis[x][y]) continue;
			vis[x][y] = 1;
			q.push((node){x, y, us + 1});
		}
	}
	cout << ans;
	return 0;
}
2022/12/19 20:54
加载中...