题解
2026-09-16 17:27:45
发布于:浙江
5阅读
0回复
0点赞
看了麻烦点个赞,不点也没关系,祝你天天开心!!!
#include <bits/stdc++.h>
using namespace std;
//定义结构体储存当前接水的人的耗时和下标
struct node{
int t,id;
}a[1010];
bool cmp(node x,node y){
if(x.t != y.t){
return x.t < y.t;//定义排序规则,接水时间短的人先去接水
}else{
return x.id < y.id;
}
}
int main(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i].t;
a[i].id = i;//给接水的人id赋值
}
sort(a + 1,a + n + 1,cmp);
double sum = 0;
for(int i = 1;i <= n;i++){
cout << a[i].id << " ";
sum += a[i].t * (n - i);
}
cout << endl;
printf("%.2f",sum / n);
return 0;
}
这里空空如也








有帮助,赞一个