zoukankan      html  css  js  c++  java
  • Decrease (Judge ver.)

    题目描述

    We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N−1 or smaller. (The operation is the same as the one in Problem D.)
    Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
    It can be proved that the largest element in the sequence becomes N−1 or smaller after a finite number of operations.
    You are given the sequence ai. Find the number of times we will perform the above operation.

    Constraints
    2≤N≤50
    0≤ai≤1016+1000
     

    输入

    Input is given from Standard Input in the following format:
    N
    a1 a2 ... aN

    输出

    Print the number of times the operation will be performed.

    样例输入

    4
    3 3 3 3

    样例输出

    0

    分析:取最大元素减至n以下,然后其余元素加上。

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #define range(i,a,b) for(int i=a;i<=b;++i)
    #define LL long long
    #define rerange(i,a,b) for(int i=a;i>=b;--i)
    #define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
    using namespace std;
    int n;
    LL num[55],ans;
    void init(){
        cin>>n;
        range(i,1,n)cin>>num[i];
    }
    void solve(){
        while(true){
            LL MAX=-2398572,pos;
            range(i,1,n)if(MAX<num[i]){
                MAX=num[i];
                pos=i;
            }
            if(MAX<n)break;
            range(i,1,n){
                if(i!=pos)num[i]+=MAX/n;
                else num[i]%=n;
            }
            ans+=MAX/n;
        }
        cout<<ans<<endl;
    }
    int main() {
        init();
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    java 实现Queue
    java 实现stack
    为什么现货白银/现货原油的报价每个交易所都不一样?
    现货交易入门之常用术语
    现货操盘手精髓语录
    现货电子交易中实物交割的概念和作用?
    关于ios对rtsp格式的流媒体支持的一些官方说明
    ProgressBar的Indeterminate属性
    安卓适配问题
    推送原理
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9318764.html
Copyright © 2011-2022 走看看