CodeForces 246B B. Increase and Decrease【思维】
2016-05-21 22:03
549 查看
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 + 1and 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
output
input
output
只要能想明白,那么这道题就是大水......
按图中给出的操作方式,只要能整除,肯定是可以平均分开的.....
否则就把多于的放在一个数上...强势背锅....
/* http://blog.csdn.net/liuke19950717 */
#include<cstdio>
int main()
{
int n;
while(~scanf("%d",&n))
{
int sum=0;
for(int i=0;i<n;++i)
{
int tp;
scanf("%d",&tp);
sum+=tp;
}
int ans=n;
if(sum%n)
{
ans=n-1;
}
printf("%d\n",ans);
}
return 0;
}
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 + 1and 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
31 4 1
output
3
只要能想明白,那么这道题就是大水......
按图中给出的操作方式,只要能整除,肯定是可以平均分开的.....
否则就把多于的放在一个数上...强势背锅....
/* http://blog.csdn.net/liuke19950717 */
#include<cstdio>
int main()
{
int n;
while(~scanf("%d",&n))
{
int sum=0;
for(int i=0;i<n;++i)
{
int tp;
scanf("%d",&tp);
sum+=tp;
}
int ans=n;
if(sum%n)
{
ans=n-1;
}
printf("%d\n",ans);
}
return 0;
}
相关文章推荐
- HIVE和HBASE区别
- Mac OS X下压力测试技巧 推荐
- caffe学习笔记(7):get the deploy.prototxt
- Justin Romberg 压缩感知:利用凸优化实现稀疏信号重建的科普
- [NOIP2005][CODEVS1106]篝火晚会(模拟+数学相关)
- 拓扑排序
- 拓扑排序
- 通信职业规划
- UVA 11879 Multiple of 17
- python后端开发视频教程学习笔记
- 发布一款原创JavaScript模板引擎插件(将html模板快速渲染成数据对应的HTML片段的工具)
- CRM
- HDU3681(Prison Break)
- (OK) using-VScode_cordova_ionic_taco-cli_Genymotion
- 关于python的self
- 16 pointFixLike
- 致自己-面试总结(机器学习、数据挖掘、自然语言处理、==)
- #ZLYD团队第二周项目总结
- 探索AutoLayout的本质和解决一些问题
- iOS中常用UI层方法总结