二维前缀和例题-激光炸弹

Posted 你可以当我没名字

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二维前缀和例题-激光炸弹相关的知识,希望对你有一定的参考价值。

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;
}

以上是关于二维前缀和例题-激光炸弹的主要内容,如果未能解决你的问题,请参考以下文章

Acwing-99-激光炸弹(二维前缀和)

Acwing 99 激光炸弹 (二维前缀和)

激光炸弹(二维前缀和)

ACwing99 激光炸弹 二维前缀和

99. 激光炸弹二维前缀和

bzoj1218: [HNOI2003]激光炸弹(DP二维前缀和)