标签:represent sid strong pos number sam figure sep cout
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 45142 | Accepted: 22306 |
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.
/********************** author: yomi date: 18.8.14 ps:现在的行为大概像以卵击石,没办法,死也要挣扎着死。 **********************/ #include <iostream> #include <queue> #include <cstdio> using namespace std; const int maxn = 150; bool vis[maxn][maxn]; int m, n; char g[maxn][maxn]; struct Pos { int x, y; }p[maxn]; int dx[3] = {-1, 0, 1}; int dy[3] = {-1, 0, 1}; void bfs(int x, int y) { queue<Pos>q; while(!q.empty()){ q.pop(); } Pos p; p.x = x; p.y = y; q.push(p); vis[x][y] = true; while(!q.empty()){ Pos now = q.front(); q.pop(); for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ int newX = now.x + dx[i]; int newY = now.y + dy[j]; if(newX<0||newX>=n||newY<0||newY>=m) continue; if(g[newX][newY]==‘.‘) continue; if(!vis[newX][newY]){ Pos New; New.x = newX; New.y = newY; q.push(New); vis[newX][newY] = true; } } } } } int main() { cin >> n >> m; int ans = 0; for(int i=0; i<n; i++){ scanf("%s", g[i]); } for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(g[i][j] == ‘W‘ && !vis[i][j]){ bfs(i, j); ans++; } } } cout << ans; return 0; } /** 10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W. **/
标签:represent sid strong pos number sam figure sep cout
原文地址:https://www.cnblogs.com/AbsolutelyPerfect/p/9476773.html