激光炸弹


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;
}
相关推荐
图灵科竞社资讯组12 分钟前
图论基础:图存+记忆化搜索
算法·图论
chuxinweihui25 分钟前
数据结构——栈与队列
c语言·开发语言·数据结构·学习·算法·链表
爱编程的鱼1 小时前
C# 结构(Struct)
开发语言·人工智能·算法·c#
啊我不会诶1 小时前
CF每日4题
算法
uhakadotcom1 小时前
人工智能如何改变医疗行业:简单易懂的基础介绍与实用案例
算法·面试·github
山北雨夜漫步2 小时前
机器学习 Day14 XGboost(极端梯度提升树)算法
人工智能·算法·机器学习
到底怎么取名字不会重复3 小时前
Day10——LeetCode15&560
c++·算法·leetcode·哈希算法·散列表
chuxinweihui3 小时前
数据结构——二叉树,堆
c语言·开发语言·数据结构·学习·算法·链表
freexyn3 小时前
Matlab自学笔记五十一:(推荐)输入参数的数量和可变数量的输入
笔记·算法·matlab
陈大大陈3 小时前
基于 C++ 的用户认证系统开发:从注册登录到Redis 缓存优化
java·linux·开发语言·数据结构·c++·算法·缓存