题意:

给你一个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的更多相关文章

  1. Codeforces Round #618 (Div. 2)

    题库链接 https://codeforces.ml/contest/1300 A. Non-zero 一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数 显然如果有0的话,必须 ...

  2. Codeforces Round #618 (Div. 1)C(贪心)

    把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 #define HAVE_STRU ...

  3. Codeforces Round #618 (Div. 1)B(几何,观察规律)

    观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...

  4. Codeforces Round #618 (Div. 1)A(观察规律)

    实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #618 (Div. 2) 小号上紫之路

    这一场涨了不少,题也比较偏思维,正好适合我 A. Non-zero 我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一 ...

  8. [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 ...

  9. 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 ...

随机推荐

  1. Qt- 图形界面应用程序的运行模式

    main() 定义主窗口 ————>fd = DefineMainWindow() 创建主窗口————>win = CreateMainWindow() 创建主窗口中的元素-----> ...

  2. Oracle VM VirtualBox - ping不通虚拟机

    问题描述 用Oracle VM VirtualBox创建虚拟机后,本机电脑ping不通虚拟机 解决方案 https://www.cnblogs.com/ranrongzhen/p/6958485.ht ...

  3. Whctf 2017 -UNTITLED- Writeup

    Whctf 2017 -UNTITLED- Writeup 转载请表明出处http://www.cnblogs.com/WangAoBo/p/7541481.html 分析: 下载下来的附件是一个py ...

  4. MFC对话框常用操作文章收藏

    1.改变控件文本 参考链接:https://blog.csdn.net/active2489595970/article/details/88856235 所有控件的文本都可以用这种方式动态改变. 2 ...

  5. Scale9Sprite 的 setCapInsets中需要注意的地方

    在设置 setCapInsets()方法的y参数的时候,不直接取cocosStudio中的y,而是取Scale9Sprite.height - cocosStudio中的y.

  6. ClassLoad

    是什么 用来加载 Class 的.它负责将 Class 的字节码形式转换成内存形式的 Class 对象.字节码可以来自于磁盘文件 .class,也可以是 jar 包里的 .class,也可以来自远程服 ...

  7. testng如何实现并发

    参考: https://www.cnblogs.com/znicy/p/6534893.html

  8. pyodbc-的一些说明

    cursor的description 可以获得一些关于表的信息 info=cursor.description 此时表中有多少列就有多少个元素,一个元素就是一列的信息(格式是tuple),所以这里的i ...

  9. 229. 求众数 II

    Q: 给定一个大小为 n 的数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素. 说明: 要求算法的时间复杂度为 O(n),空间复杂度为 O(1). 示例 1: 输入: [3,2,3] 输出: [3 ...

  10. MongoDB-2 安装与配置

    安装建议 MongoDB 可以在mac/win/linux上安装,我个人建议在linux上安装会更好,这样测试起来更方便.一般来说本地只装mysql或者MariaDB,其余的中间件一律放linux,让 ...