首页 > 其他 > 详细

解题报告 『[HNOI2003]激光炸弹(前缀和)』

时间:2019-07-17 14:24:12      阅读:45      评论:0      收藏:0      [点我收藏+]

原题地址

前缀和水题,没什么好讲的,注意横纵坐标加1。

另外此题空间有点紧。

 

代码实现如下:

技术分享图片
#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

解题报告 『[HNOI2003]激光炸弹(前缀和)』

原文:https://www.cnblogs.com/Kirisame-Marisa/p/11200114.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!