B. Increase and Decrease
来源:互联网 发布:最美的诗词 知乎 编辑:程序博客网 时间:2024/05/01 07:48
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 distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integersa1, a2, ..., an (|ai| ≤ 104) — the original array.
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
22 1
1
31 4 1
3
解题说明:考虑到一对加减运算其实是数字之间大小的转换,此题其实只需要判断所有数字之和能否被n整除即可,如果能被整除就输出n,当不能被整除时我们可以让余数作为一个单独的数字,此时相同的数共有n-1个,输出n-1
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int n,i,a;int sum;sum=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a);sum+=a;}if(sum%n==0){printf("%d\n",n);}else{printf("%d\n",n-1);}return 0;}
- B. Increase and Decrease
- Increase and Decrease--codeForces 246B
- CodeForces 246B: Increase and Decrease【水】
- Codeforces 246B Increase and Decrease 【数学】
- Codeforces 246B-Increase and Decrease【模拟】
- CodeForces 246B Increase and Decrease
- Codeforces 246B Increase and Decrease
- 【Codeforces 246B Increase and Decrease 】
- Increase and Decrease
- Increase and Decrease
- CF - 246 - B. Increase and Decrease(贪心)
- CodeForces - 246B Increase and Decrease (模拟)水
- CodeForces 246BB. Increase and Decrease【思维】
- Java Date decrease or increase
- CUIT ACM Personal Training 11.27(FM)G - Increase and Decrease
- Using DataReaders to Increase Speed and Reduce Memory
- jQuery:mouseover and Increase the Size of an Image
- jQuery:mouseover and Increase the Size of an Image
- Git系统学习(一)
- C/C++ const用法注意
- unity3D中 lightmap 与 动态光照的实时切换
- PID控制原理
- easyboot的一个严重不足
- B. Increase and Decrease
- 多种方式实现字符串/无符号数反向输出_栈_递归_头尾指针
- 国内从事CV相关的企业
- perl移植须知
- Linux获取系统时间 函数
- 轮廓 - 查找轮廓、表示轮廓、绘制轮廓
- 递归之我见
- 关于读word中table出现“无法将带 [] 的索引应用于“Interop.Word.Tables”错误的解决
- 图像形态学 - 漫水填充算法(cvFloodFill)