这个wa有点措手不及【sort函数】

P1223 排队接水

@[暴雪海南](/space/show?uid=214912) 把您的代码做了些许修改 ```cpp #include<iostream> #include<cstdio> #include<algorithm> using namespace std; struct people{ int n; int tim; bool operator < (const people a) const{ return tim < a.tim; } bool operator > (const people a) const{ return tim > a.tim; } bool operator == (const people a) const{ return tim == a.tim; } }man[1010]; int sum[1010]; int main(){ int n; double total=0; cin >> n; for (int i=1;i<=n;i++){ man[i].n=i; cin >> man[i].tim; } sort(man+1,man+n+1); for (int i=1;i<=n;i++){ sum[i]=sum[i-1]+man[i].tim; cout << man[i].n << " "; total+=sum[i-1]; } printf("\n%.2lf\n", total/(double)n); return 0; } ```
by Zenurik @ 2019-07-31 09:56:17


@[暴雪海南](/space/show?uid=214912) 您错在没有考虑清楚“等待时间”的含义,您理解的等待时间是每个人接水的时间,实际上您需要对每个人的节水时间求前缀和,因为每个人的等待时间其实是排在他前面的所有人的接水时间之和
by Zenurik @ 2019-07-31 10:01:05


@[Zenurik](/space/show?uid=47996) 大谢
by 暴雪海南 @ 2019-08-02 08:57:29


|