问题是在 gc() 上,为什么 gc() 删了就对了?求大佬解答。
#include<bits/stdc++.h>
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char gc(){
if(p1==p2)
p2=(p1=buf)+fread(buf,1,1<<21,stdin);
return *(p1++);
}
inline int read(){
int s=0,fu=1;
char ch=gc();
while(ch<'0'||ch>'9'){
if(ch=='-')fu*=-1;
ch=gc();
}
while('0'<=ch&&ch<='9'){
s=(s<<1)+(s<<3)+(ch^48);
ch=gc();
}
return s*fu;
}
inline void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const int N=1e3+10;
int n;
long long ans,sum;
struct node{
int a,id;
}t[N];
bool cmp(node x,node y){
if(x.a!=y.a)return x.a<y.a;
return x.id<y.id;
}
int main(){
n=read();
for(int i=1;i<=n;++i)
t[i].a=read(),t[i].id=i;
sort(t+1,t+n+1,cmp);
for(int i=1;i<=n;++i)
write(t[i].id),putchar(' ');
putchar('\n');
for(int i=1;i<=n;++i){
ans+=sum;
sum+=t[i].a;
}
printf("%.2lf\n",ans*1.0/n);
return 0;
}