acwing 99 二维前缀和例题-激光炸弹 [前缀和]

https://www.acwing.com/problem/content/101/

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#include<functional>
#include<numeric>
#include<ctime>
#define ini(a) memset(a,0,sizeof(a))
#define ini2(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define lowbit(x) x&(-x)
#define DBG(x) \
  (void)(cout << "L" << __LINE__ \
  << ": " << #x << " = " << (x) << '\n')
#define TIE \
	cin.tie(0);cout.tie(0)\
	ios::sync_with_stdio(false);
#define sc ll T;cin>>T;while(T--)
#define IN freopen("in.txt","r",stdin);
#define OUT srand((unsigned)time(NULL)); \
	freopen("out.txt","w",stdout);
using namespace std;
//typedef long long ll;
#define ll int
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 5005;
ll cb[maxn][maxn];

ll fastpower(ll a,ll b,ll p){
	ll res = 1;
	while(b)
    {
        if(b&1) res=res*a%p;
        b>>=1;
        a=a*a%p;
    }
    return res%p;
}


int main()
{
	for(int i=0;i<maxn;i++){
		ini(cb[i]);
	}
	int n,r;
	cin>>n>>r;
	int xx = r,yy = r;
	for(int i=0;i<n;i++){
		int x,y,w;
		cin>>x>>y>>w;
		x++,y++;
		cb[x][y] += w;
		xx = max(xx,x);// 超出r,下面用xx和yy代替 
		yy = max(yy,y);
	}
	
	for(int i=1 ; i<=xx ; i++){
		for(int j=1;j<=yy;j++){
			cb[i][j] += cb[i-1][j] + cb[i][j-1] - cb[i-1][j-1];
		}
	}
	
	ll res = -1;
	for(int i=r;i<=xx;i++){
		for(int j=r;j<=yy;j++){
			res = max(res,cb[i][j]-cb[i-r][j]-cb[i][j-r]+cb[i-r][j-r]);
		}
	}
	
	cout<<res<<"\n";
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值