Radical and Array
Time limit: 1 Sec memory limit: MB
Submit: 27 Solution:
Submitted State
Title DescriptionRadical has a array, he wants the array to the many equal numbers as possible.He can performs the following operation as many times as He wants:1.he chooses 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 1Now he want to know what maximum number of equal array elements he can get if he performs a arbitary number of such o Peration.Input
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.
Output
Print a single integer-the maximum number of equal array elements Radical can get if he performs an arbitrary number of The given operation.
Sample input
22 332 4 3
Sample output
13
After any number of times, in an array of arbitrary numbers, a number added, a number subtraction, you can get a few equal numbers
It must be very good to find the average value first. Of course we want to try to get all the numbers together as an average, and if there are bound to be some of them, then these numbers will allow us to subtract or add, so that the other numbers are reduced or added to the average. And the sum of these numbers and the remainder of the mean
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;#defineN 100005intMain () {intN, A[n], sum; while(Cin >>N) {memset (A,0,sizeof(a)); Sum=0; for(inti =0; I < n; i++) {cin>>A[i]; Sum+=A[i]; } intx = SUM/N; inty = sum%N; if(Y = =0) printf ("%d\n", N); Else{printf ("%d\n", N-1-y/(x+1)); } } return 0;}
Radical and Array