求助!!求大佬帮看
  • 板块P1141 01迷宫
  • 楼主tushanyuan
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/29 19:23
  • 上次更新2024/8/29 22:17:02
查看原帖
求助!!求大佬帮看
1398656
tushanyuan楼主2024/8/29 19:23

求大佬帮看

#include<bits/stdc++.h>
using namespace std;
string s[100010];
int n, m, ex, ey, lx, ly, sx, sy, flase = -1, ans[10000][10000],sum=0,t=1;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, na[1000][1000];
struct node {
	int x, y; //x轴 y轴
};
void bfs(int x, int y) {
	queue<node>q;//建立队列 
	node a;
	a.x = x;
	a.y = y;
	q.push(a);//输入起点
	na[x][y] = 1; //标记起点已走过 
	while (!q.empty()) {
		node now;
		now = q.front();
		q.pop();
		sum++;
		for (int i = 0; i <= 4; i++) {
			int xx = now.x + dx[i];//x轴+1 
			int yy = now.y + dy[i];//y轴+1 
			if (xx >= 1 && yy >= 1 && xx <= n && yy <= m && na[xx][yy] != 2 && na[xx][yy]!=na[now.x][now.y])//是否越界或是否走过 
			{
				na[xx][yy] = t;//标记为t 
				node al;
				al.x = xx;
				al.y = yy;
				q.push(al);//插入al 
			}
		}
	}
}
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) 
	{
		for(int j=1;j<=m;j++)
		{
			cin >> s[i][j];
			bfs(i,j);
			ans[i][j]=sum;//将ans[i][j]中的值存入sum中 
			t++;
		}
		
	}
	for(int i=1;i<=m;i++)
	{
		cin>>sx>>sy;//输入起点的x与y轴 
		cout<<ans[t];//输出ans[t]的值 
	}
}

不知道哪里错了

2024/8/29 19:23
加载中...