为什么全Re啊
查看原帖
为什么全Re啊
1533449
Doctor_10086楼主2024/11/21 15:43
#include<iostream>
using namespace std;
int goalCount, explo_len, max_size;//max_size是最大边长,记得一会将索引的max_size加一
struct Go
{
	int row;
	int column;
	int value;
};
Go goal;
int oriarr[5010][5010] = { 0 };//初始化矩阵
int sum[5010][5010] = { 0 };
void pre_sum()//前缀和矩阵
{
	sum[0][0] = oriarr[0][0];
	for (int i = 1; i < max_size; i++)
		for (int j = 1; j < max_size; j++)
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + oriarr[i][j];
}
int add(int row,int column)//传入爆破矩阵的左上角坐标值
{
	return sum[row + explo_len - 1][column + explo_len - 1] - sum[row-1][column + explo_len - 1] - sum[row + explo_len - 1][column -1] + sum[row -1][column -1];
}
int main()
{
	cin >> goalCount >> explo_len;
	cin >> goal.row >> goal.column >> goal.value;
	goal.row++;
	goal.column++;
	oriarr[goal.row][goal.column] += goal.value;
	goal.row > goal.column ? max_size = goal.row + 1 : max_size = goal.column + 1;
	for (int n = 1; n < goalCount; n++)
	{
		cin >> goal.row >> goal.column >> goal.value;
		goal.row++;
		goal.column++;
		oriarr[goal.row][goal.column] += goal.value;
		if (goal.row + 1 > max_size)max_size = goal.row + 1;
		if (goal.column + 1 > max_size)max_size = goal.column + 1;//利用循环更新矩阵最大size
	}//目标设置完成
	pre_sum();
	int ans = sum[explo_len - 1][explo_len - 1];
	for (int i = 0; i < max_size; i++)
		for (int j = 0; j < max_size; j++)
			add(i,j) > ans ? ans = add(i,j) : ans = ans;
	cout << ans << endl;
	return 0;
}
2024/11/21 15:43
加载中...