Radical and Array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.