题解
2025-11-27 20:36:07
发布于:湖南
1阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int m, n;
cin >> m >> n;
vector<vector<int>> mat(m, vector<int>(n));
vector<long long> row_sum(m, 0); // 每行的总和
vector<long long> col_sum(n, 0); // 每列的总和
// 输入矩阵并计算行总和
for (int i = 0; i < m; ++i) {
long long sum = 0;
for (int j = 0; j < n; ++j) {
cin >> mat[i][j];
sum += mat[i][j];
}
row_sum[i] = sum;
}
// 计算列总和
for (int j = 0; j < n; ++j) {
long long sum = 0;
for (int i = 0; i < m; ++i) {
sum += mat[i][j];
}
col_sum[j] = sum;
}
// 遍历每个中心点,计算十字能量和
long long max_energy = 0;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
long long current = row_sum[i] + col_sum[j] - mat[i][j];
if (current > max_energy) {
max_energy = current;
}
}
}
cout << max_energy << endl;
return 0;
}
这里空空如也







有帮助,赞一个