#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
const int dirx[] = {0, 0, 1, -1};
const int diry[] = {1, -1, 0, 0};
const int maxn = 207;
bool vis[maxn*3][maxn*3]; //离散化后是图的标记
vector<int> xx, yy; //离散化后的图,每个点代表一个长度
pair<int, int> bad[maxn]; //输入的bad_point
int cntx, cnty;
bool inside(int i, int j)
{
return i >= 0 && i < cntx && j >= 0 && j < cnty;
}
ll dfs(int i, int j)
{
ll res = 0;
res += xx[i] * 1LL * yy[j];
vis[i][j] = 1;
for(int k = 0;k < 4;k ++) {
int ni = i + dirx[k];
int nj = j + diry[k];
if(inside(ni, nj) && !vis[ni][nj]) res += dfs(ni, nj);
}
return res;
}
int main()
{
int T, Case = 0;
scanf("%d", &T);
while(T --) {
xx.clear();
yy.clear();
memset(vis, 0, sizeof(vis));
printf("Case #%d:\n", ++Case);
int n, m;
scanf("%d %d", &n, &m);
int bad_num;
scanf("%d", &bad_num);
for(int i = 1;i <= bad_num;i ++) scanf("%d %d", &bad[i].first, &bad[i].second);
unordered_map<int, int> umx;
vector<int> x;
x.push_back(0); //为了把第一个点x=1放入
x.push_back(1);
x.push_back(n);
for(int i = 1;i <= bad_num;i ++) {
x.push_back(bad[i].first);
}
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
int nx = x.size();
for(int i = 1;i < nx;i ++) {
if(x[i] - x[i-1] != 1) {
xx.push_back(x[i] - x[i-1] - 1); //把中间长度放进去
}
xx.push_back(1); //把x[i]代表的1个长度放进去
umx[x[i]] = xx.size();
}
unordered_map<int, int> umy;
vector<int> y;
y.push_back(0);
y.push_back(1);
y.push_back(m);
for(int i = 1;i <= bad_num;i ++) {
y.push_back(bad[i].second);
}
sort(y.begin(), y.end());
y.erase(unique(y.begin(), y.end()), y.end());
int ny = y.size();
for(int i = 1;i < ny;i ++) {
if(y[i] - y[i-1] != 1) {
yy.push_back(y[i] - y[i-1] - 1);
}
yy.push_back(1);
umy[y[i]] = yy.size();
}
cntx = xx.size();
cnty = yy.size();
// for(int i = 0;i < cntx;i ++) printf("%d ", xx[i]); puts("");
// for(int i = 0;i < cnty;i ++) printf("%d ", yy[i]); puts("");
for(int i = 1;i <= bad_num;i ++) {
// printf("%d %d\n", umx[bad[i].first],umy[bad[i].second] );
vis[umx[bad[i].first]-1][umy[bad[i].second]-1] = 1;
}
vector<ll> res;
for(int i = 0;i < cntx;i ++) {
for(int j = 0;j < cnty;j ++) {
if(!vis[i][j]) res.push_back(dfs(i,j));
}
}
sort(res.begin(), res.end());
n = res.size();
printf("%d\n", n);
for(int i = 0;i < n;i ++) {
printf("%lld%c",res[i], i == n - 1 ? '\n':' ');
}
}
return 0;
}
TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, TanBig dreams of a field of coconuts, and the field looks like a large chessboard which has R rows and C columns. In every cell of the field, there is one coconut. Unfortunately, some of the coconuts have gone bad. For sake of his health, TanBig will eat the coconuts following the rule that he can only eat good coconuts and can only eat a connected component of good coconuts one time(you can consider the bad coconuts as barriers, and the good coconuts are 4-connected, which means one coconut in cell (x, y) is connected to (x - 1, y), (x + 1, y), (x, y + 1), (x, y - 1).
Now TanBig wants to know how many times he needs to eat all the good coconuts in the field, and how many coconuts he would eat each time(the area of each 4-connected component).
It is guaranteed that in the input data, the first row and the last row will not have bad coconuts at the same time, the first column and the last column will not have bad coconuts at the same time.
OutputFor each test case, output "Case #x:" in the first line, where x denotes the number of test case, one integer k in the second line, denoting the number of times TanBig needs, in the third line, k integers denoting the number of coconuts he would eat each time, you should output them in increasing order.Sample Input
2 3 3 2 1 2 2 1 3 3 1 2 2Sample Output
Case #1: 2 1 6 Case #2: 1 8
题目链接:https://vjudge.net/contest/209266#problem/D
题意:给出一个N*M的地图(N,M<=1E9), 然后给你一些坏点,问你最后图中有多少联通块,并按从小到大的顺序输出这些联通快的大小。