Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std; typedef long long ll; typedef unsigned long long ull; const int mod = 1e9 + 7, N = 1e5 + 1, inf = INT_MAX;
- #define fi first
- #define se second
- #define pb push_back
- #define mp make_pair
- #define ep emplace_back
- //#define int ll
- int n, m, cnt, idx = 0;
- char a[111][111];
- bool visited[111][111];
- void dfsX(int i, int j)
- {
- if (visited[i][j] || i == 0 || j == 0 || i > n || j > m || a[i][j] != 'X')
- {
- return;
- }
- //visited[i][j] = 1;
- a[i][j] = '*';
- dfsX(i, j + 1);
- dfsX(i + 1, j);
- dfsX(i - 1, j);
- dfsX(i, j - 1);
- }
- void dfs(int i, int j)
- {
- if (a[i][j] == 'X')
- {
- cnt++;
- dfsX(i, j);
- }
- if (visited[i][j] || i == 0 || j == 0 || i > n || j > m || a[i][j] != '*')
- {
- return;
- }
- visited[i][j] = 1;
- dfs(i, j + 1);
- dfs(i + 1, j);
- dfs(i - 1, j);
- dfs(i, j - 1);
- }
- signed main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- while (cin >> m >> n && n + m)
- {
- cout << "Throw " << ++idx << endl;
- priority_queue<int, vector<int>, greater<int>>pq;
- memset(visited, 0, sizeof visited);
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- cin >> a[i][j];
- }
- }
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- if (!visited[i][j])
- {
- cnt = 0;
- dfs(i, j);
- if (cnt != 0) pq.push(cnt);
- }
- }
- }
- while (!pq.empty())
- {
- cout << pq.top();
- pq.pop();
- if (pq.size() != 0) cout << ' ';
- }
- cout << endl << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement