poj2646

简单题

View Code
   
     
#include < iostream >
#include
< cstdio >
#include
< cstdlib >
#include
< cstring >
#include
< cmath >
#include
< algorithm >
using namespace std;

#define maxn 1005

int n;
long long sum, f[maxn], f1[maxn];

int main()
{
// freopen("t.txt", "r", stdin);
while (scanf( " %d " , & n), n)
{
sum
= 0 ;
for ( int i = 0 ; i < n; i ++ )
{
double a;
scanf(
" %lf " , & a);
f[i]
= ( long long )(a * 100 + 0.5 );
sum
+= f[i];
}
sort(f, f
+ n);
reverse(f, f
+ n);
long long a, ave;
ave
= sum / n;
a
= sum % n;
for ( int i = 0 ; i < n; i ++ )
f1[i]
= ave;
for ( int i = 0 ; i < a; i ++ )
f1[i]
+= 1 ;
long long ans = 0 ;
for ( int i = 0 ; i < n; i ++ )
if (f[i] > f1[i])
ans
+= f[i] - f1[i];
printf(
" $%.2f\n " , double (ans / 100.0 ));
}
return 0 ;
}

你可能感兴趣的:(poj)