Report problem solving "[HNOI2003] laser bombs (and prefix)."

Original title Address

Prefix and water problems, nothing to talk about, pay attention to horizontal and vertical coordinates plus one.

In addition to this problem space is a little tight.

 

Code is implemented as follows:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (register int i = (a); i <= (b); i++)

const int maxn = 5e3 + 5;

int n, m, N, R;
int a[maxn][maxn];

int MAX(int a, int b) {return a > b ? a : b;}

int read() {
    int x = 0, flag = 0;
    char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') {
        flag = 1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 1) + (x << 3) + (ch ^ '0');
        ch = getchar();
    }
    return flag ? -x : x;
}

void write(int x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    N = read(), R = read();
    n = R, m = R;
    rep(i, 1, N) {
        int x, y, w;
        x = read(), y = read(), w = read();
        x += 1, y += 1;
        a[x][y] = w;
        n = MAX(n, x);
        m = MAX(m, y);
    }
    rep(i, 1, n)
        rep(j, 1, m)
            a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
    int ans = 0;
    rep(i, R, n)
        rep(j, R, m)
            ans = MAX(ans, a[i][j] - a[i - R][j] - a[i][j - R] + a[i - R][j - R]);
    write(ans);
    return 0;
}
View Code

Guess you like

Origin www.cnblogs.com/Kirisame-Marisa/p/11200114.html