简洁易懂题解
2025-12-27 10:05:35
发布于:上海
3阅读
0回复
0点赞
用排序函数使接水时间短的人排前面
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n;
long long ans;
struct node
{
int id, t;
} a[N];
bool cmp(node x, node y)
{
return x.t < y.t;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i].t;
a[i].id = i;
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; ++i)
{
cout << a[i].id << ' ';
ans += (n - i) * a[i].t;
}
printf("\n%.2f", 1.0 * ans / n);
return 0;
}
全部评论 1
制作不易,留赞后去
2025-12-27 来自 上海
0






有帮助,赞一个