zoukankan      html  css  js  c++  java
  • [Luogu] 无线网络发射器选址

    https://www.luogu.org/problemnew/show/P2038

    二维前缀和

    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    const int N = 150;
    const int n = 129;
    
    int A[N][N];
    int d, T;
    
    #define gc getchar()
    
    inline int read() {
        int x = 0; char c = gc;
        while(c < '0' || c > '9') c = gc;
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;
        return x;
    }
    
    int main() {
        d = read(); T = read();
        for(int i = 1; i <= T; i ++) {
            int x = read(), y = read(), w = read();
            A[x + 1][y + 1] = w;
        }
        for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= n; j ++)
                A[i][j] += (A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1]);
        int js(0), Max(0);
        for(int i = 1; i <= n; i ++) {
            for(int j = 1; j <= n; j ++) {
                int x_1 = max(0, i - d - 1), y_1 = max(0, j - d - 1), x_2 = min(n, i + d), y_2 = min(n, j + d);
                int W = A[x_2][y_2] - A[x_2][y_1] - A[x_1][y_2] + A[x_1][y_1];
                if(W > Max) {
                    Max = W; js = 1;
                } else if(W == Max) js ++;
            }
        }
        cout << js << " " << Max;
        return 0;
    }
  • 相关阅读:
    项目总结
    个人博客
    个人博客
    个人博客
    个人博客
    个人博客
    个人博客
    个人博客
    个人博客
    浅谈Vue与swiper轮播图框架结合小案例
  • 原文地址:https://www.cnblogs.com/shandongs1/p/8963137.html
Copyright © 2011-2022 走看看