nyoj627

Increase and Decrease

时间限制:1000 ms | 内存限制:65535 KB

难度:1

描述

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 ≤ 10^5) — the array size. The second line contains space-separated integers a1, a2, …, an (|ai| ≤ 10^4) — 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.

扫描二维码关注公众号,回复: 2613269 查看本文章

样例输入

2
2 1
3
1 4 1

样例输出

1
3
哈哈哈 难度为 1 的题, 连题目都没有看懂 代码就是那几行…

#include <stdio.h>
int main(){
    int n;
    while(scanf("%d", &n)!=EOF&&n){
        int x, ans = 0;
        for(int i=0; i<n; i++){
            scanf("%d", &x);
            ans += x;
        }
        if(ans%n == 0) printf("%d\n", n);
        else printf("%d\n", n-1);
    }
    return 0;
}

在后边评论区说 如果平均值(设为 x)是整数,就能把整个数组分成 n 个x, 否则能分成n-1个x 和一个别的数, 感觉和题目意思不一样,虽然我还没有看懂…
如果你刚好看到这个博客,又刚好看懂题目,要跟我说哦 (笔芯)。

猜你喜欢

转载自blog.csdn.net/zf2015800505/article/details/78724021