4 条题解
-
0凌艺樽 (Lawrence劳伦斯) LV 10 @ 2024-8-11 17:42:00
#include <iostream> #include <bits/stdc++.h> using namespace std; int n,s[1005];long sum; struct lp{ int id; int m; }a[1005]; int cmp(lp x,lp y) { if(x.m<y.m){ return 1; } if(x.m==y.m&&x.id<y.id)return 1; return 0; } int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i].m; s[i]=s[i-1]+a[i].m; a[i].id=i; } sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++) { cout<<a[i].id<<" "; } for(int i=1;i<=n;i++) { sum+=a[i].m*(n-i); } cout<<fixed<<setprecision(2)<<endl<<sum*1.0/n; return 0; }
-
02024-7-30 10:20:08@
#include <bits/stdc++.h> using namespace std; const int N=1e5+10; struct stu{ int id,t; }a[1005]; int cmp(stu a,stu b){ if(a.t<b.t) return 1; else return 0; } int main(){ int n; cin>>n; sort(a,a+n,cmp); 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<<" "; cout<<endl; double ans=0,time; for(int i=1;i<n;i++){ time=a[i].t*(n-i); ans+=time; } ans/=n; cout<<fixed<<setprecision(2)<<ans; }
-
02024-5-30 21:55:23@
#include<iostream> #include<iomanip> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<algorithm> #define LL long long using namespace std; const int N=1e5+10; const int Inf=0x3f3f3f3f; int n; double time1 = 1.00 * 0; struct per { int t; int num; }a[N]; bool cmp(per a, per b){ if(a.t==b.t){ return a.num<b.num; } return a.t < b.t; } int main(){ int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i].t; a[i].num = i; } sort(a + 1, a + n + 1, cmp); int sum = n - 1; for(int i = 1; i <= n; i++) { time1 += 1.00 * a[i].t * sum; sum--; cout << a[i].num << ' ' ; } time1 /= 1.00 * n; cout << endl; printf("%.2lf", time1); }
-
02024-3-24 15:37:19@
#include <bits/stdc++.h> using namespace std; const int N=1e5+10; const int INF=0x3f3f3f3f; int n; double tim = 1.00 * 0; struct person { int t; int num; }a[N]; bool cmp(person a, person b) { return a.t < b.t; } int main() { int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i].t; a[i].num = i; } sort(a + 1, a + n + 1, cmp); int sum = n - 1; for(int i = 1; i <= n; i++) { tim += 1.00 * a[i].t * sum; sum--; cout << a[i].num << ' ' ; } tim /= 1.00 * n; cout << endl; printf("%.2lf", tim); } 40分
- 1
信息
- ID
- 3007
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 328
- 已通过
- 51
- 上传者