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 ...
随机推荐
- Ubuntu下的定时备份数据库
1.编写备份数据库的shell脚本 mysqldump -uUserName -pPassword dbName >/XXX/XXXX/XXXX/fileName_$(date +%Y%m%d_ ...
- P3116 [USACO15JAN]会议时间Meeting Time
P3116 [USACO15JAN]会议时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...
- 项目中的小点_java项目某jsp页面报404
1.将项目文件夹直接放在tomcat服务器的webapps路径下 2.从一个tomcat服务器webapps下拷贝一个项目到另一个tomcat服务器webapps路径下 3.重启tomcat后,访问新 ...
- windows控制台主题美化工具-colortool
最近在win10上装了 wsl 系统,发现界面主题太挫,文件夹颜色很不清晰 . 特此在网上搜索了一下,发现了 colortool 这个工具 这是微软官方提供的用于控制台配色的程序 发布版本地址:htt ...
- Careercup - Microsoft面试题 - 24308662
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...
- leetcode 【 Pascal's Triangle 】python 实现
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,R ...
- MFC DLL 可以封装MFC的窗体 供别的MFC程序使用
MFC DLL 可以封装MFC的窗体 供别的MFC程序使用 在庞大程序分工里面 非常可取. 可以细分每个窗体就是单独的 模块. [后续不断完善]
- sqlserver执行时间和自行效率
SET STATISTICS PROFILE ON --SET STATISTICS IO ON --SET STATISTICS TIME ON declare @dtm datetime SQL语 ...
- Android数据储存之File
openFileOutStream 和 openFileInStream FileInputStream fileInputStream = openFileInput(name); 打开应用下文件 ...
- 【转】Apache Thrift - 可伸缩的跨语言服务开发框架
Apache Thrift - 可伸缩的跨语言服务开发框架 Apache Thrift 是 Facebook 实现的一种高效的.支持多种编程语言的远程服务调用的框架.本文将从 Java 开发人员角度详 ...