1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std;
const int MAXN = 60; char bmp[MAXN][MAXN]; bool vis[MAXN][MAXN]; bool searched[MAXN][MAXN];
void dot_dfs(int x, int y) { if (bmp[x][y] != 'X' or vis[x][y]) return;
vis[x][y] = searched[x][y] = true; dot_dfs(x-1, y); dot_dfs(x, y-1); dot_dfs(x+1, y); dot_dfs(x, y+1); }
int cnt;
void search(int x, int y) { if (bmp[x][y] == '.' or searched[x][y] or vis[x][y]) return;
if (bmp[x][y] == 'X' and !vis[x][y]) { ++cnt; dot_dfs(x, y); }
searched[x][y] = true; search(x-1, y); search(x, y-1); search(x+1, y); search(x, y+1); }
int main() { for (int i = 1; ; ++i) { int w, h; scanf("%d%d", &w, &h); if (!w and !h) break;
memset(bmp, '.', sizeof(bmp)); memset(vis, false, sizeof(vis)); memset(searched, false, sizeof(searched)); for (int j = 1; j <= h; j++) { scanf("%s", bmp[j] + 1); bmp[j][w+1] = '.'; }
vector<int> ans;
for (int j = 1; j <= h; j++) for (int k = 1; k <= w; k++) if (bmp[j][k] != '.' and !searched[j][k]) { cnt = 0; search(j, k); if (cnt > 0 and cnt < 7) ans.push_back(cnt); }
sort(ans.begin(), ans.end());
printf("Throw %d\n", i); for (vector<int>::iterator j = ans.begin(); j != ans.end(); ++j) { if (j != ans.begin()) putchar(' '); printf("%d", *j); } printf("\n\n"); } return 0; }
|