0
已解决
乔俊驰
资深守护
资深守护
1251咋写?最后的等待时间不太会啊
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
int time,pos;
}a[10005];
bool cmp(node a,node b){
if(a.time!=b.time){
return a.time<b.time;
}
return a.pos<b.pos;
}
int main(){
long long n;
double sum=0.00;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].time;
a[i].pos=i;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++){
int cnt=0;
cout<<a[i].pos<<' ';
for(int j=i+1;j<=n;j++){
cnt++;
}
sum+=a[i].time*cnt;
}
printf("\n%.2f\n",sum/n);
return 0;
}