# hdu5753 2016 Multi-University Training Contest 3 Permutation Bo 解题报告

742人阅读 评论(0)

code：

#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<ctime>
#include<cmath>
#include<string>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 1100;
int c[maxn],n;

int main()
{
while( scanf("%d",&n) != EOF )
{
for( int i=1;i<=n;i++ ) scanf("%d",&c[i]);
if( n == 1 )
{
printf("%lf\n",double(c[1]));
continue;
}
if( n == 2 )
{
printf("%lf\n",double(c[1]+c[2])/2);
continue;
}
int s1,s2;
double ret1,ret2;
ret1 = ret2 = 0.0;  s1 = s2 = 0;
for( int i=1;i<=n;i++ )
{
for( int j=1;j<=n;j++ )
if( i != j )
{
if( i > j ) s1 ++;
if( i < j ) s2 += j-2;
}
}
ret1 = double(s1)*double( c[1]+c[n] );
for( int i=2;i<n;i++ ) ret2 += double(s2)*double(c[i]);
double r1 = ret1/n/(n-1)
,r2 = ret2/n/(n-1)/(n-2);
printf("%lf\n",r1+r2);
}

return 0;
}


友链
个人资料
等级：
访问量： 14万+
积分： 6104
排名： 5028