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\) ...
随机推荐
- 自己定义View之Chart图标系列(1)——点阵图
近期要做一些图表类的需求,一開始就去github上看了看,发现开源的图表框架还是蛮多的.可是非常少有全然符合我的需求的.另外就是使用起来比較麻烦.所以就决定自己来造轮子了~~~ 今天要介绍的就是And ...
- Hadoop集群管理--保证集群平稳地执行
本篇介绍为了保证Hadoop集群平稳地执行.须要深入掌握的知识.以及一些管理监控的手段,日常维护的工作. HDFS 永久性数据结构 对于管理员来说.深入了解namenode,辅助namecode和da ...
- ORA-01003: no statement parsed
环境:delphi 5.BDE.oracle10 delphi里面用tStoreProc调用存储过程出现ORA-01003: no statement parsed. 解决方法:tStoreProc. ...
- bzoj1066【SCOI2007】蜥蜴
1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2512 Solved: 1238 [Submit][Statu ...
- php实现模拟登陆
在不考虑验证码的情况一下,php实现模拟登陆,网上给的办法通常是採用curl来模拟实现,可是curl实现的是server端与server端建立了会话,仅仅能模拟登陆之后获取登陆之后的数据.无法将coo ...
- 判断DataGridView滚动条是否滚动到当前已加载的数据行底部
private void dataGridView1_Scroll(object sender, ScrollEventArgs e) { if (e.ScrollOrientation == S ...
- C# DevExpress GridControl使用方法
一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 ().gridView.AddNe ...
- 关于props default 数组/对象的默认值应当由一个工厂函数返回
export default {props: { xAxisData: { type: Array, default: [] }, },这是我的代码 报错是Invalid default va ...
- element-ui表格控件前端分页方法
<div id="app"> <el-table :data="tableData.slice((currentPage-1)*pageSize,cur ...
- LeetCode 223 Rectangle Area(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...