zoukankan      html  css  js  c++  java
  • Radical and array

    Radical and array

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 46  解决: 27
    [提交][状态]

    题目描述

    Radical has an array , he wants the array to have as many equal numbers as possible.
    He can performs the following operation as many times as he wants:
    1.he chooses two elements of the array a[i] , a[j] (i!=j).
    2.he simultaneously increases number a[i] by 1 and decreases number a[j] by 1
    Now he want to know what maximum number of equal array elements he can get if he performs an arbitary number of such operation.

    输入

    The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (ai ≤ 100000) — the original array.

    输出

    Print a single integer — the maximum number of equal array elements Radical can get if he performs an arbitrary number of the given operation.

    样例输入

    2
    2 3
    3
    2 4 3
    

    样例输出

    1
    3

    经过任意次,在数组里任意取数,一个数相加,一个数相减后,最多可以得到几个相等的数
    先求出平均值想必是极好哒。我们当然想尽量把所有数都凑成平均值,如果一定会有的数凑不成,那这些数就可以让我们随意拿来减或者加,以便让其他数减或加凑成平均值。而这些数之和与平均值的余数
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    
    #define N 100005
    
    int main()
    {
        int n, a[N], sum;
    
        while(cin >> n)
        {
            memset(a, 0, sizeof(a));
            sum = 0;
    
            for(int i = 0; i < n; i++)
            {
                cin >> a[i];
                sum += a[i];
            }
            int x = sum / n;
            int y = sum % n;
    
            if(y == 0)
                printf("%d
    ", n);
            else{
                printf("%d
    ", n-1-y/(x+1));
            }
        }
        return 0;
    }
    让未来到来 让过去过去
  • 相关阅读:
    设计模式 里氏替换原则
    java队列
    java 多线程
    设计模式-里氏替换原则
    设计模式-单一职责原则
    一、概念
    六、序列化和反序列化(对象流)
    七、随机访问文件流
    五、包装流
    四、字符输入输出流
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4689691.html
Copyright © 2011-2022 走看看