Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
15544 马德理666 [贪心算法]排队接水 C++ 运行出错 0 MS 244 KB 598 2023-04-23 22:16:26

Tests(0/1):


#include<bits/stdc++.h> using namespace std; struct l{ int a,b; }c[10000]; int cmp(const l & g,const l & h){ if(g.a!=h.a) return g.a<h.a; return g.b<h.b; } int main(){ freopen("water.in","r",stdin); freopen("water.out","w",stdout); long long n; double d=0,e=0; cin>>n; for(int i=0;i<n;i++) { cin>>c[i].a;c[i].b=i+1; } sort(c,c+n,cmp); for(int i=0;i<n;i++) cout<<c[i].b<<" "; cout<<endl; for(int i=0;i<n;i++) e=e+c[i].a*(n-i-1); e=e/n; printf("%0.2f",e); return 0; }


测评信息: