标签:contain script ace mes href which print for where
Description
Input
Output
Sample Input
10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W.
Sample Output
3
Hint
Source
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> using namespace std; #define ll long long int n, m, sum;; char position[100+8][100+8], mov[8][2] = {0,1, 1,0, 0,-1, -1,0, 1,1, 1,-1, -1,-1, -1,1}; struct coordinate { int x, y; }; void bfs(int a, int b) { queue<coordinate>q; coordinate miao; miao.x = a; miao.y = b; q.push(miao); while(!q.empty()) { coordinate fir; fir = q.front(); coordinate next; q.pop();//在这里就要弹出,不然后面会插入很多东西 for(int i = 0; i<8; i++) { next.x = fir.x+mov[i][0]; next.y = fir.y+mov[i][1]; if(next.x >= 0 && next.x<n && next.y >= 0 && next.y<m && position[next.x][next.y] == ‘W‘) { position[next.x][next.y] = ‘.‘; q.push(next); } } } } int main() { scanf("%d%d", &n, &m); getchar(); sum = 0; for(int i = 0; i<n; i++) { for(int j = 0; j<m; j++) { scanf("%c", &position[i][j]); } getchar(); } for(int i = 0; i<n; i++) for(int j = 0; j<m; j++) if(position[i][j] == ‘W‘) { position[i][j] = ‘.‘; bfs(i, j); sum++; } printf("%d\n", sum); return 0; }
标签:contain script ace mes href which print for where
原文地址:https://www.cnblogs.com/RootVount/p/10452986.html