Atcoder AtCoder Regular Contest 079 E - Decrease (Judge ver.)
E - Decrease (Judge ver.)
Time limit : 2sec / Memory limit : 256MB
Score : 600 points
Problem Statement
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
Input is given from Standard Input in the following format:
N
a1 a2 ... aN
Output
Print the number of times the operation will be performed.
Sample Input 1
4
3 3 3 3
Sample Output 1
0
Sample Input 2
3
1 0 3
Sample Output 2
1
Sample Input 3
2
2 2
Sample Output 3
2
Sample Input 4
7
27 0 0 0 0 0 0
Sample Output 4
3
Sample Input 5
10
1000 193 256 777 0 1 1192 1234567891011 48 425
Sample Output 5
1234567894848
模拟一下就可以了
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll n,k,x,m;
priority_queue<ll>q;
int main()
{
ios();
scanf("%lld",&n);
for(int i=;i<=n;i++)
{
scanf("%lld",&x);
q.push(x);
}
k=;
while(q.top()+k>=n)
{
ll ans=q.top()+k;
q.pop();
m=ans/n;
ans-=m*n;
k+=m;
q.push(ans-k);
}
printf("%lld\n",k);
return ;
}
Atcoder AtCoder Regular Contest 079 E - Decrease (Judge ver.)的更多相关文章
- 【贪心】AtCoder Regular Contest 079 E - Decrease (Judge ver.)
每次将最大的数减到n以下,如此循环直到符合题意. 复杂度大概是n*n*log?(?). #include<cstdio> #include<iostream> #include ...
- 【构造】AtCoder Regular Contest 079 D - Decrease (Contestant ver.)
从n个t变化到n个t-1,恰好要n步,并且其中每一步的max值都>=t,所以把50个49当成最终局面,从这里开始,根据输入的K计算初始局面即可. #include<cstdio> # ...
- 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 Regular Contest 079 F - Namori Grundy
对每个点的取值都取最小的可能值. 那个图最多一个环,非环的点的取值很容易唯一确定. 对于环上的点v,其最小可能取值要么是mex{c1,c2,...,ck}(ci这些是v直接相连的非环点)(mex是). ...
- AtCoder Regular Contest 079
C题,刚开始以为遍历整个树,后来发现二重循环判断就行了 #include<map> #include<set> #include<cmath> #include&l ...
- Decrease (Judge ver.)
题目描述 We have a sequence of length N consisting of non-negative integers. Consider performing the fol ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
随机推荐
- 杭电 HDU ACM 2795 Billboard(线段树伪装版)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- quick 3.3载入Spine问题
近期项目要升级到Quick 3.3, 而且使用了Spine作为动画编辑器, 在此把升级过程中.有关quick 3.3 载入Spine遇到的坑在此记录一下. 1.Spine版本号问题 首先Quick 3 ...
- 面对即将终止支持的server你还能做些什么
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXF1c2hp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- 线程池系列三:ThreadPoolExecutor讲解
三.一个用队列处理线程池例子 package demo; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; ...
- UVALive - 6269 Digital Clock 模拟
UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...
- mysql安装遇到的坑
安装mysql的三步: mysqld --initialize-insecure mysqld -install net start mysql 中间遇到了坑, 看这篇文章完美的解决了,记录一下 .以 ...
- 【Django】视图系统
目录 FBV 与 CBV 给视图加装饰器 使用装饰器装饰CBV 关于dispatch()方法 Request对象 与 Response对象 request对象 response对象 @ *** 一个视 ...
- img下面的留白解决
在做网页的时候经常会出现一个令人困惑的现象.那就是行内元素和块级元素之间会出现“留白”.就是块级元素中明明只有一个行内元素,但行内元素却不会铺满块级元素.像这个例子: “留白”出现的原因 行内元素默认 ...
- 喜马拉雅FM
import requestsimport jsonstart_url ='https://www.ximalaya.com/revision/play/album?albumId=3595841&a ...
- 洛谷—— P1328 生活大爆炸版石头剪刀布
https://www.luogu.org/problem/show?pid=1328 题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在< ...