原题链接:https://www.acwing.com/problem/content/description/4228/
//简单Flood Fill
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
const int N=110;
int n,m;
char g[N][N];
int dx[8]={-1,-1,0,1,1,1,0,-1},dy[8]={0,1,1,1,0,-1,-1,-1};
void bfs(int a,int b)
{
queue<PII> q;
q.push({a,b});
while(q.size()){
auto t=q.front();
q.pop();
for(int i=0;i<8;i++){
int x=dx[i]+t.x,y=dy[i]+t.y;
if(x<0||x>=n||y<0||y>=m) continue;
if(g[x][y]=='*') continue;
g[x][y]='*';
q.push({x,y});
}
}
}
int main()
{
while(scanf("%d%d",&n,&m),n||m)
{
for(int i=0;i<n;i++) scanf("%s",&g[i]);
int cnt=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(g[i][j]=='@'){
bfs(i,j);
cnt++;
}
}
printf("%d\n",cnt);
}
}
标签:石油,12,int,while,continue,include,储备,define
From: https://www.cnblogs.com/linearlearn/p/17284603.html