Loading

B - The writing on the wall【18南京网络赛】

B - The writing on the wall

题意

\(n \times m\) 的区域中不含 黑块 的矩形的数量

思路

枚举矩形的右下角,然后向前扫合法的左上角

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10, M = 110;

int T, n, m, k;
int mp[N][M], up[M];

int main() {
	scanf("%d", &T);int c = 0;
	while (T--) {
		scanf("%d%d%d", &n, &m, &k);
		for (int i = 1;i <= m;i++)up[i] = 0;
		for (int i = 1;i <= n;i++)for (int j = 1;j <= m;j++)mp[i][j] = 0;
		while (k--) {
			int x, y;scanf("%d%d", &x, &y);
			mp[x][y] = 1;
		}

		ll ans = 0;
		for (int i = 1;i <= n;i++) {
			for (int j = 1;j <= m;j++) {
				if (mp[i][j]) {
					up[j] = i;
					continue;
				}
				int h = i;
				for (int k = j;k >= 1;k--) {
					h = min(h, i - up[k]);
					ans += h;
				}
			}
		}
		printf("Case #%d: %lld\n", ++c, ans);
	}
}
posted @ 2020-12-01 21:47  —O0oO-  阅读(84)  评论(0编辑  收藏  举报