简单题
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#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 ;
}
#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 ;
}