题目描述

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[],ans;
void init(){
cin>>n;
range(i,,n)cin>>num[i];
}
void solve(){
while(true){
LL MAX=-,pos;
range(i,,n)if(MAX<num[i]){
MAX=num[i];
pos=i;
}
if(MAX<n)break;
range(i,,n){
if(i!=pos)num[i]+=MAX/n;
else num[i]%=n;
}
ans+=MAX/n;
}
cout<<ans<<endl;
}
int main() {
init();
solve();
return ;
}

Decrease (Judge ver.)的更多相关文章

  1. Atcoder AtCoder Regular Contest 079 E - Decrease (Judge ver.)

    E - Decrease (Judge ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem Statem ...

  2. 【贪心】AtCoder Regular Contest 079 E - Decrease (Judge ver.)

    每次将最大的数减到n以下,如此循环直到符合题意. 复杂度大概是n*n*log?(?). #include<cstdio> #include<iostream> #include ...

  3. Atcoder At Beginner Contest 068 D - Decrease (Contestant ver.)

    D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...

  4. Atcoder arc079 D Decrease (Contestant ver.) (逆推)

    D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...

  5. 【构造】AtCoder Regular Contest 079 D - Decrease (Contestant ver.)

    从n个t变化到n个t-1,恰好要n步,并且其中每一步的max值都>=t,所以把50个49当成最终局面,从这里开始,根据输入的K计算初始局面即可. #include<cstdio> # ...

  6. AtCoder刷题记录

    构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和 ...

  7. arc079

    D. Decrease (Contestant ver.) 大意: 每次操作选一个最大数$-n$,其余数全$+1$. 要求构造一个序列$a$, 使得恰好$k$次操作后最大值不超过$n-1$. 只要让$ ...

  8. 【AtCoder】ARC079

    ARC079题解 C - Cat Snuke and a Voyage #include <bits/stdc++.h> #define fi first #define se secon ...

  9. SPOJ 15. The Shortest Path 堆优化Dijsktra

    You are given a list of cities. Each direct connection between two cities has its transportation cos ...

随机推荐

  1. TCP/IP网络编程之多种I/O函数

    send和recv函数 在之前的学习中,我们在不少示例中用到send和recv这两个函数,但一直没有详细解释过着两个函数中每个参数的含义.本节将介绍Linux平台下的send&recv函数 # ...

  2. cakephp中使用 find('count')方法

    对于find('count',array('group'=>'user_id')); Model.php中这样描述: /** * Handles the before/after filter ...

  3. Azure Active Directory中的特权身份管理如何运作?

    [TechTarget中国原创] 用户权限不是平等的.有些用户需要有大量权利和特权——通常这些都是管理员.企业在允许特权用户进行管理以及支持活动时,还需要意识到特权用户也有可能犯错.他们会犯错.他们可 ...

  4. [netty4][netty-common]FastThreadLocal及其相关类系列

    FastThreadLocal 概述: ThreadLocal的一个特定变种改善,有更好的存取性能. 内部采用一个数组来代替ThreadLocal内部的hash表来存放变量.虽然这看起来是微不足道的, ...

  5. MYSQL学习心得(转)

    适合有SQL SERVER或ORACLE基础的人看,有对比,学习更有效果 转自:http://www.cnblogs.com/lyhabc/ 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习 ...

  6. Windows下MySQL8.0.11.0安装教程

    1.mysql下载地址:https://dev.mysql.com/downloads/installer/ 2.下载安装MySQL 8.0.11.0 https://cdn.mysql.com//D ...

  7. Leetcode 655.输出二叉树

    输出二叉树 在一个 m*n 的二维字符串数组中输出二叉树,并遵守以下规则: 行数 m 应当等于给定二叉树的高度. 列数 n 应当总是奇数. 根节点的值(以字符串格式给出)应当放在可放置的第一行正中间. ...

  8. struts ValueStack 详解

    一.ValueStack     1.ValueStack是一个接口,在struts2中使用OGNL(Object-Graph Navigation Language)表达式实际上是使用        ...

  9. 【转】iTween for Unity

    http://www.cnblogs.com/zhaoqingqing/p/3833321.html?utm_source=tuicool&utm_medium=referral 你曾经在你的 ...

  10. python基础-集合小结

    Python-基础-集合小结 集合 简介 声明 常用操作 成员关系 新增删除 集合间操作 其他 补充 集合 简介 python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和 ...