为什么会报错
  • 板块学术版
  • 楼主syx2542514722
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/6/26 12:28
  • 上次更新2024/6/26 16:44:11
查看原帖
为什么会报错
1321882
syx2542514722楼主2024/6/26 12:28
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int m,n,g[10010][10010],cnt,dx[8]={-1,-1,0,1,1,1,0,-1},dy[8]={-0,1,1,1,0,-1,-1,-1};
typedef pair<int,int>PII; 
void bfs(int sx,int sy){
	queue<PII>q;
	q.push({sx,sy});
	g[sx][sy]=0;
	
	while(!q.empty()){
		auto h=q.front();
		q.pop();
		for(int i=0;i<8;++i){
			int x=h.first+dx[i];
			int y=h.second+dy[i];
			if(x>0&&x<=n&&y>0&&y<=n&&g[x][y]){
				q.push({x,y});
				g[x][y]=0;
			}
		} 
	}
}
int main(){
	cin>>m>>n;
	for(int i=1;i<=m;++i){
		cin>>g[i];
	}
	for(int i=1;i<=m;++i){
		for(int j=1;j<=n;++i){
			if(g[m][n]){
				cnt++;
				bfs(m,n);
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
} 
2024/6/26 12:28
加载中...