mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-10-17 21:42:25 +00:00
feat: 添加P7301.cpp解题代码实现
实现一个矩阵处理算法,计算行和列中奇偶位置元素和的最大值,并输出两者中的较大值
This commit is contained in:
parent
5546dd0eed
commit
0937a7a512
34
src/10/16/P7301.cpp
Normal file
34
src/10/16/P7301.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
using ll = int32_t;
|
||||
|
||||
const ll maxn = 1005;
|
||||
ll n,ans,ans1,a[maxn][maxn];
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin>>n;
|
||||
for(ll i=1;i<=n;i++){
|
||||
ll n1=0,n2=0;
|
||||
for(ll j=1;j<=n;j++){
|
||||
std::cin>>a[i][j];
|
||||
if(j&1)n1+=a[i][j];
|
||||
else n2+=a[i][j];
|
||||
}
|
||||
ans+=std::max(n1,n2);
|
||||
}
|
||||
|
||||
for(ll j=1;j<=n;j++){
|
||||
ll n1=0,n2=0;
|
||||
for(ll i=1;i<=n;i++){
|
||||
if(i&1)n1+=a[i][j];
|
||||
else n2+=a[i][j];
|
||||
}
|
||||
ans1+=std::max(n1,n2);
|
||||
}
|
||||
std::cout<<std::max(ans1,ans)<<"\n";
|
||||
}
|
Loading…
Reference in New Issue
Block a user