题意:
中文题。
思路:
并查集,周长变化可以算出来。
代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1111111;
int pa[MAXN];
int Find(int x) {
return x == pa[x] ? x : pa[x] = Find(pa[x]);
}
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
bool vis[1005][1005];
int main() {
//freopen("in.txt", "r", stdin);
int n;
scanf("%d", &n);
for (int i = 0; i < 1000 * 1000; i++) pa[i] = i;
memset(vis, false, sizeof(vis));
int now = 0, C = 0;
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
int id1 = x * 1000 + y, cnt = 0;
vis[x][y] = true;
for (int j = 0; j < 4; j++) {
int nx = x + dx[j], ny = y + dy[j];
if (nx < 0 || nx >= 1000 || ny < 0 || ny >= 1000 || !vis[nx][ny]) continue;
int id2 = nx * 1000 + ny;
int p1 = Find(id1), p2 = Find(id2);
if (p1 != p2) {
pa[p1] = p2;
if (cnt > 0) --now;
}
++cnt;
}
if (cnt == 0) {
now++;
C += 4;
}
else if (cnt == 1) {
C += 2;
}
else if (cnt == 3) {
C -= 2;
}
else if (cnt == 4) {
C -= 4;
}
printf("%d %d %d\n", now, i, C);
}
return 0;
}