Radical and array
生活随笔
收集整理的這篇文章主要介紹了
Radical and array
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Radical and array
時間限制: 1 Sec??內(nèi)存限制: 128 MB
提交: 46??解決: 27
[提交][狀態(tài)]
題目描述
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經(jīng)過任意次,在數(shù)組里任意取數(shù),一個數(shù)相加,一個數(shù)相減后,最多可以得到幾個相等的數(shù)
先求出平均值想必是極好噠。我們當(dāng)然想盡量把所有數(shù)都湊成平均值,如果一定會有的數(shù)湊不成,那這些數(shù)就可以讓我們隨意拿來減或者加,以便讓其他數(shù)減或加湊成平均值。而這些數(shù)之和與平均值的余數(shù) #include<iostream> #include<cstdio> #include<cstring>using namespace std;#define N 100005int 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", n);else{printf("%d\n", n-1-y/(x+1));}}return 0; }
?
轉(zhuǎn)載于:https://www.cnblogs.com/Tinamei/p/4689691.html
總結(jié)
以上是生活随笔為你收集整理的Radical and array的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】Android中定时器的3种实现方
- 下一篇: [CODEVS1205]单词反转