mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2026-02-03 17:27:18 +00:00
feat: 添加P7521.cpp解决算法问题
实现一个算法来计算给定数组中的最大模数结果。对输入数组进行排序、去重和反转处理,然后通过三重循环计算满足条件的最大模数值。
This commit is contained in:
parent
0de21a3bd3
commit
4ec66e7a1e
43
src/11/27/P7521.cpp
Normal file
43
src/11/27/P7521.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
|
#include <vector>
|
||||||
|
using ll = int64_t;
|
||||||
|
#define printf
|
||||||
|
ll n,ans;
|
||||||
|
std::vector<ll> a;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
std::iostream::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::cin>>n;
|
||||||
|
a.resize(n);
|
||||||
|
for(ll i=0;i<n;i++)std::cin>>a[i];
|
||||||
|
|
||||||
|
std::sort(a.begin(),a.end());
|
||||||
|
a.erase(std::unique(a.begin(),a.end()),a.end());
|
||||||
|
n=a.end()-a.begin();
|
||||||
|
std::reverse(a.begin(),a.end());
|
||||||
|
|
||||||
|
for(auto i:a){
|
||||||
|
printf("%lld ",i);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
for(ll k=0;k<n;k++){
|
||||||
|
if(a[k]<=ans)break;
|
||||||
|
for(ll i=0;i<n;i++){
|
||||||
|
for(ll j=0;j<n;j++){
|
||||||
|
if(i==j||i==k||j==k)continue;
|
||||||
|
if(a[i]+a[j]<a[k])break;
|
||||||
|
if(ll nxt=(a[i]+a[j])%a[k];nxt>=ans){
|
||||||
|
ans=nxt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out:;
|
||||||
|
std::cout<<ans<<"\n";
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user