激光炸弹


title: 激光炸弹

date: 2023-12-14 19:42:59
tags: 前缀和
categories: 算法进阶指南

题目链接

− − > --> −−> 传送门

题目大意

思路

代码

cpp 复制代码
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz size()
#define bpt __builtin_popcountll

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

const int N = 5e3 +10, mod = 1e9 + 7;

int g[N][N];

int main()
{
    int n,R;
    cin >> n >> R;
    R = min(R,5001);
    for(int i = 1; i <= n;  i++){
        int x,y,c;
        cin >> x >> y >> c;
        g[++x][++y] += c;
    }
    
    for(int i = 1; i <= 5001; i ++){
        for(int j = 1; j <= 5001; j ++){
            g[i][j] = g[i-1][j] +g[i][j - 1] - g[i-1][j-1] + g[i][j];
        }
    }
    
    int ans = 0;
    for(int i = R ; i <= 5001; i ++){
        for(int j  = R ; j <= 5001; j ++){
            ans = max(ans,g[i][j] - g[i-R][j] - g[i][j - R] + g[i - R][j - R]);
        }
    }
    cout << ans << endl;
    return 0;
}
相关推荐
何以解忧,唯有..4 小时前
预订酒店问题
算法
No8g攻城狮4 小时前
【算法】什么是 DFS 与 BFS 及他们的区别
算法·深度优先·宽度优先
zww89491114 小时前
家政派单系统实战指南:从需求分析到智能调度算法落地
算法·需求分析
手写码匠4 小时前
华为云Flexus+DeepSeek征文|Dify 多 Agent 评测实战:用 DeepSeek-R1 当裁判,打造多智能体系统的自动化质量保障体系
人工智能·深度学习·算法·aigc
ZC跨境爬虫4 小时前
LeetCode 88. 合并两个有序数组(双指针详解 + Java Python 实现)
java·python·算法·leetcode
Nil2084 小时前
leetcode 238除了自身以外数组的乘积
数据结构·算法·leetcode
土司大王4 小时前
LeetCode hot100——最长连续序列
数据结构·算法·leetcode
caimouse4 小时前
ReactOS 图形系统分析(17):区域填充 — EngPaint / IntEngPaint(paint.c)
c语言·开发语言·算法
生态学者5 小时前
Ecological Indicators | 机场鸟调的新方法:用 AWM-PC1 读懂干扰梯度下的鸟类群落
人工智能·算法·r语言·微信公众平台
Herbert_hwt5 小时前
第六章 Java深入理解接口、函数式接口与lambda表达式
java·开发语言·算法