• B


    B - The writing on the wall

    题意

    (n imes 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
    ", ++c, ans);
    	}
    }
    
  • 相关阅读:
    非空约束
    leetcode208
    leetcode207
    leetcode395
    leetcode116
    leetcode105
    leetcode131
    leetcode73
    leetcode200
    leetcode17
  • 原文地址:https://www.cnblogs.com/sduwh/p/14070971.html
Copyright © 2020-2023  润新知