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
| #include <iostream> #include <vector> #include <algorithm> using namespace std; int m, n, k, x1, x2, y1, y2, arr[102][102], xx, yy, dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0}, tmp, ans; vector<int> area; void dfs(int x, int y) { arr[y][x] = 1; for(int i = 0; i < 4; i++) { xx = x + dx[i]; yy = y + dy[i]; if(xx >= n || yy >= m || xx < 0 || yy < 0 || arr[yy][xx]) continue; tmp++; dfs(xx, yy); } } int main() { cin >> m >> n >> k; while(k--) { cin >> x1 >> y1 >> x2 >> y2; for(int x = x1; x < x2; x++) for(int y = y1; y < y2; y++) arr[y][x] = 1; } for(int i = 0; i < m; i++) for(int j = 0; j < n; j++) if(!arr[i][j]) { tmp = 1; dfs(j, i); area.push_back(tmp); ans++; } cout << ans << endl; sort(area.begin(), area.end()); for(int i = 0; i < area.size(); i++) cout << area[i] << " "; }
|