题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
int a[maxn][maxn];
int main(void) {
int n=2, r=1;
cin>>n>>r;
int x, y, c, maxX=r, maxY=r;
for(int i = 1; i <= n; i++) {
cin>>x>>y>>c;
a[++x][++y] += c;
maxX = max(maxX, x);
maxY = max(maxY, y);
}
for(int i = 1; i <= maxX; i++){
for(int j = 1; j <= maxY; j++){
a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + a[i][j];
}
}
int ans = -2147483647;
for(int i = r; i <= maxX; i++){
for(int j = r; j <= maxY; j++){
ans = max(ans, a[i][j] - a[i - r][j] - a[i][j - r] + a[i - r][j - r]);
}
}
cout<<ans;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
blablabla