Decrease (Judge ver.)
题目描述
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
输入
N
a1 a2 ... aN
输出
样例输入
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.)的更多相关文章
- Atcoder AtCoder Regular Contest 079 E - Decrease (Judge ver.)
E - Decrease (Judge ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem Statem ...
- 【贪心】AtCoder Regular Contest 079 E - Decrease (Judge ver.)
每次将最大的数减到n以下,如此循环直到符合题意. 复杂度大概是n*n*log?(?). #include<cstdio> #include<iostream> #include ...
- Atcoder At Beginner Contest 068 D - Decrease (Contestant ver.)
D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...
- Atcoder arc079 D Decrease (Contestant ver.) (逆推)
D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...
- 【构造】AtCoder Regular Contest 079 D - Decrease (Contestant ver.)
从n个t变化到n个t-1,恰好要n步,并且其中每一步的max值都>=t,所以把50个49当成最终局面,从这里开始,根据输入的K计算初始局面即可. #include<cstdio> # ...
- AtCoder刷题记录
构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和 ...
- arc079
D. Decrease (Contestant ver.) 大意: 每次操作选一个最大数$-n$,其余数全$+1$. 要求构造一个序列$a$, 使得恰好$k$次操作后最大值不超过$n-1$. 只要让$ ...
- 【AtCoder】ARC079
ARC079题解 C - Cat Snuke and a Voyage #include <bits/stdc++.h> #define fi first #define se secon ...
- SPOJ 15. The Shortest Path 堆优化Dijsktra
You are given a list of cities. Each direct connection between two cities has its transportation cos ...
随机推荐
- mybatis特殊字符处理
在mybatis 的mapper.xml文件中特殊字符处理方式 仅供参考 出处:http://yaobenzhang.blog.163.com/blog/static/214395113201561 ...
- App 设计技巧
http://www.360doc.com/content/14/1120/18/21412_426730809.shtml http://veryui.diandian.com/post/2013- ...
- 67、activity中调用fragment内部自定义的方法
fragment: /** * author: Created by zzl on 15/11/19. */ @SuppressLint("validFragment") publ ...
- 61、请求数据进行gizp压缩
1.请求时进行头部处理 /** * 设置通用消息头 * * @param request */ public void setHeader(HttpUriRequest request) { // r ...
- 【Container With Most Water】cpp
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- IOS开发学习笔记020-练习总结
自己做了一遍,现在再复习一下,总结一下. 最终效果如下 1.新建一个工程Single View Application 总体如下 不过要关闭自动布局功能 这是按下设置按钮显示的界面默认 ...
- [oldboy-django][5python基础][高级特性]generator生成器
# 生成器基础 - 定义 在循环的时候不断推算下一个元素的值,而不是一下子创建空间存储所有元素,这样节省空间. 并且在适当的条件结束循环,这种一边循环一边计算的机制,称为generator生成器 - ...
- [oldboy-django][2深入django]xss攻击 + csrf
1 xss攻击 xss攻击(跨站脚本攻击,用户页面提交数据来盗取cookie) - 慎用safe, 和mark_safe -- 如果要用,必须要过滤 - 定义: 用户提交内容,在页面展示用html显示 ...
- 论文笔记《ImageNet Classification with Deep Convolutional Neural Network》
一.摘要 了解CNN必读的一篇论文,有些东西还是可以了解的. 二.结构 1. Relu的好处: 1.在训练时间上,比tanh和sigmod快,而且BP的时候求导也很容易 2.因为是非饱和函数,所以基本 ...
- codevs 1690 开关灯 线段树区间更新 区间查询Lazy
题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这些路灯全是关着的,六点之后,会有M(2<=m<=100000)个人 ...