Algorithm-Renewed

This commit is contained in:
e2hang
2025-09-13 22:37:17 +08:00
parent 265b8af720
commit 7b6acef275
14 changed files with 778 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
#include <iostream>
#include <utility>
#include <iomanip>
#include <set>
using namespace std;
struct cmp{
bool operator()(const pair<int, int>& a, const pair<int, int>& b) const{
if(a.second != b.second) return a.second < b.second;
else return a.first < b.first;
}
};
int main(){
set<pair<int, int>, cmp> s;
int n;
cin >> n;
int tmp;
double all = 0;
for(int i = 0; i < n; i++){
cin >> tmp;
s.emplace(make_pair(i + 1, tmp));
}
auto x = s.begin();
for(int i = 0; i < n; i++){
cout << (*x).first << " ";
all += (n - i - 1) * (*x).second;
x++;
}
cout << endl;
cout << fixed << setprecision(2) << all / n << endl;
return 0;
}