激光炸弹


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;
}
相关推荐
Not Dr.Wang42210 分钟前
自动控制系统稳定性研究及判据分析
算法
VT.馒头10 分钟前
【力扣】2722. 根据 ID 合并两个数组
javascript·算法·leetcode·职场和发展·typescript
ffqws_16 分钟前
A*算法:P5507 机关 题解
算法
执着25937 分钟前
力扣hot100 - 108、将有序数组转换为二叉搜索树
算法·leetcode·职场和发展
2501_9011478339 分钟前
学习笔记:单调递增数字求解的迭代优化与工程实践
linux·服务器·笔记·学习·算法
AI科技星41 分钟前
张祥前统一场论核心场方程的经典验证-基于电子与质子的求导溯源及力的精确计算
线性代数·算法·机器学习·矩阵·概率论
kebijuelun1 小时前
ERNIE 5.0:统一自回归多模态与弹性训练
人工智能·算法·语言模型·transformer
历程里程碑1 小时前
普通数组----最大子数组和
大数据·算法·elasticsearch·搜索引擎·排序算法·哈希算法·散列表
52Hz1182 小时前
力扣230.二叉搜索树中第k小的元素、199.二叉树的右视图、114.二叉树展开为链表
python·算法·leetcode
苦藤新鸡2 小时前
56.组合总数
数据结构·算法·leetcode