2 solutions
-
1
#include <bits/stdc++.h> using namespace std; struct node { int t, id; } a[1010]; bool cmp(node x,node y) { return x.t < y.t; } int n, i, j; double ans; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i].t; a[i].id = i; } sort(a + 1, a + n + 1, cmp); for (i = 1; i <= n; i++) cout << a[i].id << " "; cout << endl; for (j = n - 1; j >= 1; j--) { i = n - j; ans += a[i].t * j; } cout << fixed << setprecision(2) << ans / n << endl; return 0; }
-
1
发个题解
#include<bits/stdc++.h> using namespace std; int n; double sum=0; struct peo{ int num; int t; }m[164017]; bool cmp(peo a,peo b){ return a.t<b.t; } int main(){ cin>>n; for(int i=1;i<=n;i++){ m[i].num=i; cin>>m[i].t; } sort(m+1,m+n+1,cmp); for(int i=1;i<=n;i++){ cout<<m[i].num<<' '; } cout<<'\n'; for(int i=n-1;i>=1;i--){ sum+=m[n-i].t*i; } sum/=n; cout<<fixed<<setprecision(2)<<sum; return 0; }
- 1
Information
- ID
- 1120
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 3
- Tags
- # Submissions
- 47
- Accepted
- 27
- Uploaded By