码迷,mamicode.com
首页 > 其他好文 > 详细

L - Oil Deposits

时间:2018-04-29 15:28:05      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:nod   turn   namespace   div   stream   style   amp   ==   pre   

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <queue>
 4 using namespace std;
 5 
 6 int n, m;
 7 const int maxn = 105;
 8 string s[maxn];
 9 int f[8][2] = { {0, 1},{1, 0},{-1, 0},{0, -1},{1, 1},{-1, -1},{1, -1},{-1, 1} };
10 
11 struct node{
12     int x, y;
13 }now, last;
14 queue<node>q;
15 void bfs(int x, int y){
16     while(!q.empty())   q.pop();
17     last.x = x;
18     last.y = y;
19     q.push(last);
20     s[x][y] = *;
21     while(!q.empty()){
22         last = q.front(); q.pop();
23         for(int i = 0;i < 8;i++){
24             now.x = last.x + f[i][0];
25             now.y = last.y + f[i][1];
26 
27             if(now.x < 0 || now.y < 0|| now.x >= n || now.y >= m|| s[now.x][now.y] == *)
28                 continue;
29             q.push(now);
30             s[now.x][now.y] = *;
31         }
32     }
33 }
34 
35 int main(){
36     while(cin >> n >> m){
37         if(n == 0 && m == 0 )
38             break;
39         for(int i = 0;i < n;i++)
40             cin >> s[i];
41         int ans = 0;
42         for(int i = 0;i < n;i++){
43             for(int j = 0;j < m;j++){
44                 if(s[i][j] == @){
45                     ans++;
46                     bfs(i, j);
47                 }
48             }
49         }
50         cout << ans << endl;
51     }
52     return 0;
53 }

 

L - Oil Deposits

标签:nod   turn   namespace   div   stream   style   amp   ==   pre   

原文地址:https://www.cnblogs.com/jaydenouyang/p/8970925.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!