| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 83994 | sh25_shenpy | 排队打水问题 | C++ | 通过 | 0 MS | 252 KB | 1120 | 2026-02-05 14:59:00 |
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> using namespace std; struct Person { int id; int time; }; bool compare(const Person& a, const Person& b) { if (a.time != b.time) { return a.time < b.time; } return a.id < b.id; } int main() { int n; cin >> n; vector<Person> people(n); for (int i = 0; i < n; ++i) { people[i].id = i + 1; cin >> people[i].time; } sort(people.begin(), people.end(), compare); // 输出排队顺序 for (int i = 0; i < n; ++i) { if (i > 0) cout << " "; cout << people[i].id; } cout << endl; // 计算总等待时间(包含自身接水时间,匹配样例定义) long long total_wait = 0; int sum_time = 0; for (int i = 0; i < n; ++i) { sum_time += people[i].time; total_wait += sum_time; } // 输出平均等待时间,保留两位小数 double avg_wait = (double)total_wait / n; cout << fixed << setprecision(2) << avg_wait << endl; return 0; }