对于排队接水(P1223)的一点理解

#include <iostream>
#include <cstdio>
#include<cmath>
#include <algorithm>
using namespace std;
double sum,ans;
long int n;
long long int t[1001];
int main(int argc, const char * argv[])//字符串数组,用来存放指向字符串参数的指针数组,每一个元素指向一个参数
{
cin>>n;
int x;
for(int i=1;i<=n;i++)
{
cin>>x;
t[i]=x*1001+i;
}
sort(t+1,t+1+n);
for(int j=1;j<=n;j++)
{
cout<<t[j]%1001<<" ";
sum+=t[j]/1001*(n-j);
}
cout<<endl;
ans=sum/n;
printf("%0.2lf",ans);
return 0;
}

猜你喜欢

转载自www.cnblogs.com/this-is-M/p/10408328.html
今日推荐