Files
python/LuoGu/RuMen/P2356.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

31 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<bits/stdc++.h> //万能头文件
using namespace std;
int main() {
int n;
cin >> n;
int a[n][n], sum[1000 * 1000] = {0}; //sum用来记录矩阵每一个容身之处的分数
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
int aa = 0; //因为不知道一共有多少个sum所以用aa计数
for (int i = 0; i < n; i++) { //在矩阵中找无敌人的地点
for (int j = 0; j < n; j++) {
if (a[i][j] == 0) {
for (int k = 0; k < n; k++) {
sum[aa] += a[k][j]; //统计所在列获得的分数
}
for (int k = 0; k < n; k++) {
sum[aa] += a[i][k]; //统计所在行获得的分数
}
aa++; //统计完一个点的分数后使用数组的下一位进行存储
}
}
} //sort真好用
sort(sum, sum + n * n, greater<int>()); //把每个点获得的分数从大到小排序
cout << sum[0] << endl; //输出最大分数
return 0;
}