Algorithm-Renewed
This commit is contained in:
32
Algorithm/Greedy/P1223 排队接水.cpp
Normal file
32
Algorithm/Greedy/P1223 排队接水.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user