Codeforces 246B Increase and Decrease
来源:互联网 发布:淘宝上的摩托车靠谱吗 编辑:程序博客网 时间:2024/05/21 22:44
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.
Example
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
题意:给定n个数,每次可以将其中不相同的两个数一个加一,一个减一。问你最多可以得到多少个相同的数。
思路:整除时可以得到n个,而不能整除时可以得到n-1个。(或k=sum%n;n=n-k;)
#include<stdio.h>int main(){ int n,a,i,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;}
- 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
- 嵌入式开源GUI项目
- IE8下ajaxFileUpload上传文件成功,但不进入回调函数,而是提示下载信息
- https配置从tomcat迁移到Nginx
- Android常用代码片段
- LocationManager定位国内偏移,WGS-84、GCJ-02、BD-09之间转换
- Codeforces 246B Increase and Decrease
- 架构设计:系统存储(6)——MySQL数据库性能优化(2)
- SDL2 with OpenGL
- bzoj2141: 排队(树套树 或 分块)
- Mysql的增删改查
- 使用科大讯飞SDK实现语音功能
- C/C++通过WMI和系统API函数获取系统硬件配置信息
- CentOS Linux解决Device eth0 does not seem to be present
- 数据库主外键关联