【Codeforces 246B Increase and Decrease 】
来源:互联网 发布:流程图描述KMP算法 编辑:程序博客网 时间:2024/05/22 09:41
B. Increase and Decrease
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, …, an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
从给出的数组中任选两个数~一个加一~一个·减一~最后得到的相同的数最多有几个~
把所有数加起来~如果能被N整除~通过加一减一最后肯定能得到N个~反之~一直拿同一个数和其他数~运算~最后得到N - 1 个~
AC代码:
#include<cstdio>typedef long long LL;int main(){ int N,a; LL ans = 0; scanf("%d",&N); for(int i = 1 ; i <= N; i++){ scanf("%d",&a); ans += a; } if(ans % N == 0) printf("%d\n",N); else printf("%d\n",N - 1); return 0;}
- 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 】
- CodeForces - 246B Increase and Decrease (模拟)水
- B. Increase and Decrease
- CodeForces 246BB. Increase and Decrease【思维】
- CF - 246 - B. Increase and Decrease(贪心)
- Increase and Decrease
- Increase and Decrease
- Java Date decrease or increase
- CUIT ACM Personal Training 11.27(FM)G - Increase and Decrease
- 【CODEFORCES】 D. Increase Sequence
- Maximum Increase CodeForces
- Codeforces 466 D. Increase Sequence
- J2SE第九章——线程同步
- 第十五周项目—两个字符串的连接
- 安卓字体流光特效,炫酷控件
- JPA学习(二)
- 总结 2016.12.10
- 【Codeforces 246B Increase and Decrease 】
- NoiOpenJudge 2.2 Pell数列
- NRF24L01实现msp430单片机通信(SPI)
- EasyUI DataGrid表格双击获取该行数据—笔记
- MySQL数据库(索引的操作)
- libyuv转换
- 四天学会mongoDB(第三天 细说高级操作)
- 2.泛型类的功能-C#高级编程
- HashMap实现原理分析