【HNOI 2003】 激光炸弹

【题目链接】

            https://www.lydsy.com/JudgeOnline/problem.php?id=1218

【算法】

            二维前缀和

【代码】

          

#include<bits/stdc++.h>
using namespace std;
#define calc(xa,ya,xb,yb) s[xb][yb] - s[xa-1][yb] - s[xb][ya-1] + s[xa-1][ya-1]

int n,r,i,j,x,y,c,mx;
int s[5005][5005];

template <typename T> inline void read(T &x)
{
    int f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}
template <typename T> inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x/10);
    putchar(x%10+'0');
}
template <typename T> inline void writeln(T x)
{
    write(x);
    puts("");
}

int main() {
        
        read(n); read(r);
        for (i = 1; i <= n; i++)
        {
                read(x); read(y); read(c);
                s[x+1][y+1] += c;    
        } 
        for (i = 1; i <= 5001; i++)
        {
                for (j = 1; j <= 5001; j++)
                {
                        s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + s[i][j];        
                }        
        }
        for (i = r; i <= 5001; i++)
        {
                for (j = r; j <= 5001; j++)
                {
                        if (calc(i-r+1,j-r+1,i,j) > mx)
                                mx = calc(i-r+1,j-r+1,i,j);    
                }        
        }
        writeln(mx);
        
        return 0;
    
}

 

转载于:https://www.cnblogs.com/evenbao/p/9234686.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值