45pts求调(玄关!!!)
查看原帖
45pts求调(玄关!!!)
1281479
1234ZSL楼主2025/2/5 15:30

代码如下:

#include <bits/stdc++.h>
using namespace std;
int c[5005][4005];
int main() {
	int n,m;
	cin >> n >> m;
	int maxi= 0,maxj = 0;
	for (int i=1;i<=n;++i) {
		int x,y,z;
		cin >> x >> y >> z;
		c[x][y] = z;
		maxi = max(x,maxi);
		maxj = max(y,maxj);
	}
	++maxi;
	++maxj;
	for (int i=0;i<maxi;++i) {
		for (int j=0;j<maxj;++j) c[i][j] = c[i - 1][j] + c[i][j - 1] + c[i][j] - c[i - 1][j - 1];
	}
	int maxs = -2147483647;
	for (int i=0;i<maxi-m;++i) {
		for (int j=0;j<maxj-m;++j) {
			int x = i,y = j,x2 = x + m - 1,y2 = y + m - 1;
			maxs = max(maxs, c[x2][y2] - c[x - 1][y2] - c[x2][y - 1] + c[x - 1][y - 1]);
//			cout << s[x2][y2] - s[x - 1][y2] - s[x2][y - 1] + s[x - 1][y - 1] << " ";
		}
	}
	cout << maxs;
	return 0;	
}

调了必关!!!

2025/2/5 15:30
加载中...