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
  • 相关阅读:
    jQuery 文本框得失焦点应用
    .NET 学习书籍推荐
    Android开发常见问题小结
    如何使用别人项目源码
    Android相关学习资料整理
    Android网络文件下载模块整理
    父类方法扩展
    继承后构造函数的关系
    私有属性和私有方法l
    面向对象
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9318764.html
Copyright © 2011-2022 走看看