日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Radical and array

發(fā)布時間:2024/4/17 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。