You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1020 B

2 years ago
#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;
}