Codeforces Round #618 E
题意:
给你一个n的数组,你可以进行无数次,选择区间使得区间内的值相加,然后区间的所有的值变成平均值。
使得最后数组的字典序最小
思路:
最后的数组一定是单调递增的,只要它比之前的平均值数大,就不会操作,如果比他小,需要进行操作到符合它的范围
用单调递减栈进行操作
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define it register int
#define inf 0x3f3f3f3f
#define lowbit(x) (x)&(-x)
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
const int maxn=1e6+;
int n,m,t;
double a[maxn],ans[maxn];
int l[maxn],len[maxn];
int main(){
scanf("%d",&n);
for(it i=;i<=n;i++){
scanf("%lf",&a[i]);len[i]=;
}
it top=;l[]=;
for(it i=;i<=n;i++){
double now=a[i],sum=a[i];
while(top>= && a[l[top]]>now){
len[i]+=len[l[top]];
sum+=a[l[top]]*len[l[top]];
now=sum/len[i];
top--;
}
a[i]=sum/len[i];
l[++top]=i;
}
it l1=;
while(top>=){
for(it i=;i<=len[l[top]];i++){
ans[++l1]=a[l[top]];
}top--;
}
for(it i=l1;i;i--){
printf("%.10lf\n",ans[i]);
}
return ;
}
补一道,单调栈
题意:
求数组n,连续的k,从头到n-k,其中每一段中最大的数字是什么
样例
5 3
1 5 3 4 2
输出
5
5
4
思路
从前到后,存进去比sta.top大的值,和已经存进去并且在区间内的值
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define it register int
#define inf 0x3f3f3f3f
#define lowbit(x) (x)&(-x)
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 998244353
const int maxn=2e6+;
int n,k;
int a[maxn],sta[maxn],ans[maxn],pos[maxn];
int main() {
scanf("%d%d",&n,&k);
for(it i=;i<n;i++){
scanf("%d",&a[i]);
}
int top=,t=;sta[top]=a[];pos[top]=;
for(it i=;i<k-;i++){
while(top>= && (a[i]>sta[top] || i-k>=pos[top])){
top--;
}
sta[++top]=a[i];pos[top]=i;
}
for(it i=k-;i<n;i++){
while(top>= && (a[i]>sta[top] || i-k>=pos[top])){
top--;
}
sta[++top]=a[i];pos[top]=i;
it c=;while(i-k>=pos[c]){c++;}
printf("%d\n",sta[c]);
}
return ;
}
Codeforces Round #618 E的更多相关文章
- Codeforces Round #618 (Div. 2)
题库链接 https://codeforces.ml/contest/1300 A. Non-zero 一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数 显然如果有0的话,必须 ...
- Codeforces Round #618 (Div. 1)C(贪心)
把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 #define HAVE_STRU ...
- Codeforces Round #618 (Div. 1)B(几何,观察规律)
观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...
- Codeforces Round #618 (Div. 1)A(观察规律)
实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...
- Codeforces Round #618 (Div. 2)A. Non-zero
Guy-Manuel and Thomas have an array aa of nn integers [a1,a2,…,an ]. In one step they can add 11 to ...
- Codeforces Round #618 (Div. 2)C. Anu Has a Function
Anu has created her own function ff : f(x,y)=(x|y)−y where || denotes the bitwise OR operation. For ...
- Codeforces Round #618 (Div. 2) 小号上紫之路
这一场涨了不少,题也比较偏思维,正好适合我 A. Non-zero 我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一 ...
- [CF百场计划]#2 Codeforces Round #618 (Div. 2)
A. Non-zero Description: Guy-Manuel and Thomas have an array \(a\) of \(n\) integers [\(a_1, a_2, \d ...
- Codeforces Round #618 (Div. 2)-B. Assigning to Classes
Reminder: the median of the array [a1,a2,-,a2k+1] of odd number of elements is defined as follows: l ...
随机推荐
- memcached和redis对比
关于memcached和redis的使用场景,总结如下:两者对比: redis提供数据持久化功能,memcached无持久化. redis的数据结构比memcached要丰富,能完成场景以外的事情: ...
- codeforces 1282 E. The Cake Is a Lie (dfs+构造)
链接:https://codeforces.com/contest/1282/problem/E 题意:给的是一张平面图,是一个n边形,每次可以切一刀,切出一个三角形,最终切成n-2个三角形.题目给出 ...
- js -- 高阶函数的使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- javascript当中Function用法
4)Function用法 例 3.4.1 <head> <meta http-equiv="content-type" content="text ...
- 关于Excute()方法,与in参数连用
DECLARE @tempTbl TABLE(OrderNo VARCHAR(50)) DECLARE @orderNos VARCHAR(4000) SET @orderNos='''3f1a82c ...
- 关于testbench
区别与verilog HDL代码,主要留意以下内容: 1,语言本身支持的特征和可综合的代码是两回事,不是所有verilog语言都可以转化为硬件的. 2,testbench作为top module,不需 ...
- AcWing 两个简单的位运算操作
//是柱状数组的一个基操作 //返回n的最后一位1:lowbit(n) = n & -n //比如 x=1010 那么返回10 x=101000 返回1000 #include<bits ...
- Html5 Canvas 使用
<div> <img id="scream" src="dali.jpg" alt="The Scream" width= ...
- bootstrap联动校验(转载)
接触bootstrapvalidator时间不久,最近需要多个字段共同验证,网上查了一下未找到,查阅api文档,发现确实可以实现. 先看dom <div class="form-gro ...
- 转载:EQ--biquad filter
http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt https://arachnoid.com/BiQuadDesigner/index.html ...