题目
acm 一道水题:Increase and Decrease 求思路
Description
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
he chooses two elements of the array ai, aj (i ≠ j); he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two
Description
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
he chooses two elements of the array ai, aj (i ≠ j); he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two
提问时间:2021-04-05
答案
先用HASH记录每个数字的出现个数,然后找出出现最多的那个数字ai,数目为MAX1,算出剩下的数字个数N,若是奇数,则ANS=MAX1+N-1,若是偶数,则判断平均数与那个数字ai的大小,若相等则ANS=MAX1+N,否则ANS=MAX1+N-1
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点
- 1看不见的爱 读后感
- 2Locate the appropriate location and select one of the language choices available
- 3三个正方体木块黏合成如图所示的模型,它们的棱长分别是1dm,2dm.3dm,要在模型上涂油漆,如果黏合部分不涂,求模型的涂漆面积.
- 4袋中有5种颜色的小球若干个,从中至少取出()个才能保证一定有5个球颜色相同.
- 5考拉白天睡觉晚上吃树叶 Koalas sleep ____ ,b
- 6已知一个水分子的质量约为3×10﹣26次方kg,那么1g水大约有多少个水分子?如果20滴水约1mL……
- 7英语翻译
- 8∫ x2/(1+x2)2 dx 求不定积分? 要快~
- 9Only if both sides accept the agreement will a lasting peace be established in this region
- 10夜空西南方向有一颗很亮的星是金星吗