社区讨论
排队接水求调
灌水区参与者 3已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lzqa8tos
- 此快照首次捕获于
- 2024/08/12 08:55 2 年前
- 此快照最后确认于
- 2024/08/12 10:11 2 年前
C
#include<bits/stdc++.h>
using namespace std;
struct Man{
int id;
int time;
};
vector<Man> man;
bool cmp(const Man& a, const Man& b){
return a.time < b.time;
}
int main(){
int n;
cin >> n;
man.resize(n);
vector<int> timeNeeds(n,0);
for (int i = 1;i <= n;i++){
man[i].id = i;
cin >> man[i].time;
}
sort(man.begin(), man.end(),cmp);
for (int i = 1; i <= n; i++)
cout << man[i].id << " ";
cout << endl;
double s = 0;
for (int i = 1;i <= n;i++){
s += man[i].time * (n - i);
}
printf("%.2f",s / n);
return 0;
}
序号能正常输出,大蒟蒻实在是看不出来问题了,每次调试都有不同的结果。
回复
共 5 条回复,欢迎继续交流。
正在加载回复...