Radical and array
时间限制: 1 Sec 内存限制: 128 MB
提交: 46 解决: 27
[提交][状态]
题目描述
Radical has an array , he wants the array to have as many equal numbers as possible.
He can performs the following operation as many times as he wants:
1.he chooses two elements of the array a[i] , a[j] (i!=j).
2.he simultaneously increases number a[i] by 1 and decreases number a[j] by 1
Now he want to know what maximum number of equal array elements he can get if he performs an arbitary number of such operation.
输入
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (ai ≤ 100000) — the original array.
输出
Print a single integer — the maximum number of equal array elements Radical can get if he performs an arbitrary number of the given operation.
样例输入
2
2 3
3
2 4 3
样例输出
1 3
经过任意次,在数组里任意取数,一个数相加,一个数相减后,最多可以得到几个相等的数
先求出平均值想必是极好哒。我们当然想尽量把所有数都凑成平均值,如果一定会有的数凑不成,那这些数就可以让我们随意拿来减或者加,以便让其他数减或加凑成平均值。而这些数之和与平均值的余数
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 100005 int main() { int n, a[N], sum; while(cin >> n) { memset(a, 0, sizeof(a)); sum = 0; for(int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } int x = sum / n; int y = sum % n; if(y == 0) printf("%d ", n); else{ printf("%d ", n-1-y/(x+1)); } } return 0; }