bzoj 1218: [HNOI2003]激光炸弹

二维前缀和

#include<bits/stdc++.h>
using namespace std;
const int N=5005;
int f[N][N];
int get_(int x1,int y1,int x2,int y2){
    return f[x1][y1]-f[x1][y2-1]-f[x2-1][y1]+f[x2-1][y2-1];
}
int main(){
    int n,r;
    scanf("%d%d",&n,&r);
    for(int i=1;i<=n;++i){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        f[x+1][y+1]=z;
    }
    int ans=0;
    for(int i=1;i<=5001;++i){
        for(int j=1;j<=5001;++j){
            f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
            ans=max(ans,get_(i,j,max(1,i-r+1),max(1,j-r+1)));
        }
    }
    printf("%d",ans);
    return 0;
}
View Code

 

posted @ 2018-12-16 22:15  lqsno1  阅读(114)  评论(0编辑  收藏  举报