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
  • 相关阅读:
    遗传学详解及Matlab算法实现
    (转)非常好的理解遗传算法的例子
    Halcon学习笔记之支持向量机(二)
    Hough 变换
    主元分析PCA理论分析及应用
    Retinex图像增强算法
    Halcon学习笔记之支持向量机(一)
    阿里云OSS安装使用问题
    JS中双击和单击事件冲突解决
    JavaScript正则表达式应用---replace()
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9318764.html
Copyright © 2011-2022 走看看