You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
int a [ 105 ] ;
// 这个贪心算法太有意思了~
int main ( ) {
//输入+输出重定向
freopen ( " ../1267.txt " , " r " , stdin ) ;
int n , i , avg , count , sum = 0 ;
count = 0 ;
cin > > n ;
//读入数据,并计算出平均数
for ( i = 0 ; i < n ; i + + ) {
cin > > a [ i ] ;
sum + = a [ i ] ;
}
avg = sum / n ;
//从前面第一个开始,就计算出距离平均数都差多少
for ( i = 0 ; i < n ; i + + ) {
a [ i ] = a [ i ] - avg ;
}
//遍历所有的堆
for ( i = 0 ; i < n - 1 ; i + + ) {
if ( a [ i ] ! = 0 ) //如果等于0的话就不用管了;
{
a [ i + 1 ] = a [ i ] + a [ i + 1 ] ; //不管是正还是负,都向后面一个要
a [ i ] = 0 ; //把自己标识为与平均值的差为0, 就是达标了
count + + ; //要了一次加1一次
} else
continue ;
}
cout < < count < < endl ;
//关闭文件
fclose ( stdin ) ;
return 0 ;
}