Decrease (Judge ver.)

题目描述

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然后其他的数+1,但是这样在写程序的时候会发现很复杂,程序做了很多重复性的工作,通过认真分析,完全可以把最大的数一次性的减到N以下,然后计算减的次数,然后其他的数就加上减的次数,会发现这两个操作其实是等价的,显然后者会让程序算法优化很多,下面是程序代码

#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;

int main(){
	bool flag=true;//下方程序循环判断的标志,如果最大的值小于n的话,那么就结束循环
	ll  ans=0;

	vector<ll>ve;
	int n;
	cin>>n;
  ll temporary;
	int position;
	ll x;
	for(int i=0;i<n;i++){
		cin>>x;
		ve.push_back(x);//把数据读入到一个不定长数组里
		
	}
	ll max;
	while(flag){
	max=ve[0];//首先假定第一个元素为最大值
	position=0;//同时也假定最大元素的坐标是0;
	
	for(int i=1;i<n;i++){
	if(ve[i]>max){
		max=ve[i];//开始寻找数组中的最大值,并记录它的位置
	position=i;
	}
	}
	if(max>=n){
	temporary=max/n;//计算减到n以下需要的次数
	ve[position]%=n; 
	ans+=temporary;
	for(int i=0;i<n;i++){
		if(position==i)
			continue;
		ve[i]+=temporary;//把其他的元素加上上边减到n一下需要的次数
	}
	}
	else{
	cout<<ans<<endl;
	flag=false;
	}
	}
return 0;

}

 

### Prometheus Decrease Function Usage and Examples In the context of Prometheus, the `decrease` function calculates the decrease in the input time series over a specified range as defined by the range vector selector. This is particularly useful when monitoring metrics that are expected to decline or where one needs to measure how much a counter has decreased within a given timeframe. The syntax for using this function follows: ```promql decrease(<metric>[<duration>]) ``` For instance, if there exists a metric named `http_requests_total`, which tracks the total number of HTTP requests processed since the server started, applying the `decrease` function can help determine how many fewer requests were made during any specific interval compared to an earlier period[^1]. A practical example would be calculating the reduction in request volume between two points in time: ```promql decrease(http_requests_total[5m]) ``` This query returns the difference in values recorded at the start and end of each five-minute window for the past hour, effectively showing drops in traffic volumes over those intervals. When working with Redis cluster metrics through exporters monitored via Prometheus, similar logic applies. One might want to track decreases in certain performance indicators like connection attempts or failed operations per second across nodes within the cluster[^4]. To visualize such data changes more intuitively, integrating Grafana dashboards provides powerful graphing capabilities alongside rich visualization options tailored specifically towards understanding trends derived from PromQL queries including ones utilizing functions like `decrease()`. --related questions-- 1. How does the increase function differ from decrease in Prometheus? 2. What types of scenarios benefit most from using the decrease function on Redis metrics? 3. Can you provide examples of custom alerts based on decreasing trends identified through Prometheus queries? 4. In what ways can Grafana enhance interpretation of results obtained from using the decrease function?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值