Files
python/TangDou/XiTi/1265.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

43 lines
1020 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
struct Person {
int n; //第几个人
int t; //接水时间
};
Person person[101];
bool cmp(const Person &x, const Person &y) {
return x.t < y.t;
}
int main() {
//输入+输出重定向
freopen("../1265.txt", "r", stdin);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
Person p;
p.n = i;
cin >> p.t;
person[i] = p;
}
//排序
sort(person + 1, person + n + 1, cmp); //注意排序时a+n+1的用法和用意
//总的等待时间
int sum = 0;
for (int i = 1; i <= n; i++) { //因为最后一个人不需要等待所以不是i<=n
cout << person[i].n << " ";
if (i < n) sum += (n - i) * person[i].t; //注意有几个人,就要乘以几
}
cout << endl;
//保留两位小数
cout << setiosflags(ios::fixed) << setprecision(2) << 1.0 * sum / n << endl;
//关闭文件
fclose(stdin);
return 0;
}