6
2025-04-07 11:56:26
发布于:江苏
#include <bits/stdc++.h>
using namespace std;
struct Person {
int id;
int time;
};
bool compare(const Person &a, const Person &b) {
return a.time < b.time;
}
int main() {
int n;
cin >> n;
vector<Person> people(n);
for (int i = 0; i < n; ++i) {
cin >> people[i].time;
people[i].id = i + 1;
}
sort(people.begin(), people.end(), compare);
vector<int> order(n);
vector<int> waitTimes(n);
int totalWaitTime=0;
int currentTime=0;
for (int i = 0; i < n; ++i) {
order[i] = people[i].id;
waitTimes[i] = currentTime;
totalWaitTime += currentTime;
currentTime += people[i].time;
}
double averageWaitTime = static_cast<double>(totalWaitTime) / n;
for (int i = 0; i < n; ++i) {
cout << order[i];
if (i != n - 1) {
cout << " ";
}
}
cout << endl;
cout << fixed << setprecision(2) << averageWaitTime << endl;
return 0;
}
这里空空如也
有帮助,赞一个