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
  • 相关阅读:
    2-字符串篇(4)
    1-数组篇(2)
    Neo4j-电影图(演员与电影之间的流行文化联系)
    NLP(相关资料)
    Oracle中的rank()函数使用
    PostgreSQL入门
    风格迁移论文理解--A Neural Algorithm of Artistic Style
    【Math】复数表示和傅里叶变换
    github资源使用--程序员必备
    【TF-2-3】Tensorflow-可视化(TensorBoard)
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9318764.html
Copyright © 2011-2022 走看看