激光炸弹


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;
}
相关推荐
mit6.8246 小时前
bfs|栈
算法
CoderYanger7 小时前
优选算法-栈:67.基本计算器Ⅱ
java·开发语言·算法·leetcode·职场和发展·1024程序员节
jllllyuz7 小时前
Matlab实现基于Matrix Pencil算法实现声源信号角度和时间估计
开发语言·算法·matlab
稚辉君.MCA_P8_Java7 小时前
DeepSeek 插入排序
linux·后端·算法·架构·排序算法
多多*7 小时前
Java复习 操作系统原理 计算机网络相关 2025年11月23日
java·开发语言·网络·算法·spring·microsoft·maven
.YM.Z9 小时前
【数据结构】:排序(一)
数据结构·算法·排序算法
Chat_zhanggong3459 小时前
K4A8G165WC-BITD产品推荐
人工智能·嵌入式硬件·算法
百***48079 小时前
【Golang】slice切片
开发语言·算法·golang
墨染点香9 小时前
LeetCode 刷题【172. 阶乘后的零】
算法·leetcode·职场和发展
做怪小疯子9 小时前
LeetCode 热题 100——链表——反转链表
算法·leetcode·链表