answer

wangruihao 2023-11-18 13:46:56 7 返回题目

#include <bits/stdc++.h> using namespace std; int n; double ans = 0; struct node { int x, t; } a[1010]; 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].x = i; } sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n; i++) ans = ans + a[i].t * (n - i + 1); printf("\n%.2lf", ans * 1.0 / n); return 0; }

{{ vote && vote.total.up }}