记录编号 174286 评测结果 AAAAAAAAAA
题目名称 [UVa 572] 油田 最终得分 100
用户昵称 Gravatar0 是否通过 通过
代码语言 C++ 运行时间 0.008 s
提交时间 2015-07-31 21:12:19 内存使用 0.33 MiB
显示代码纯文本
# include <cstdio>
# include <iostream>
# include <cstring>
# include <queue>

using namespace std;

const int MAXN = 101;

int n,m,sum;
char a[MAXN][MAXN];
int gx[8] = {-1,-1,0,1,1,1,0,-1};
int gy[8] = {0,1,1,1,0,-1,-1,-1};

void BFS(int i,int j) {
	queue < pair<int,int> > q;
	q.push(make_pair(i,j));
	a[i][j] = '*';
	while(!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for(int s = 0; s < 8; ++s) {
			int qx = x + gx[s];
			int qy = y + gy[s];
			if(a[qx][qy] == '@')
				if(qx >= 1 && qx <= n && qy >=1 && qy <= m) {
					q.push(make_pair(qx,qy));
					a[qx][qy] = '*';
				}
		}
	}
}

void work(int n,int m) {
	int i,j;
	for(i = 1; i <= n; ++i )
		for(j = 1; j <= m; ++j)
			cin >> a[i][j];
	for(i = 1; i <= n; ++i)
		for(j = 1; j <= m; ++j)
			if(a[i][j] == '@') {
				sum ++;
				BFS(i,j);
			}
	cout << sum << endl;
	memset(a,'\0',sizeof(a));
	sum = 0;
}

int main() {
	freopen("oild.in","r",stdin);
	freopen("oild.out","w",stdout);
	while(cin >> n >> m && n && m) work(n,m);
	return 0;
}