题意:

给你一个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. Mybaits的中的对象映射(包含仅有基本数据类型的属性的和对象类型的属性的)

    转:https://blog.csdn.net/cjt20100/article/details/46547617. 1 constructor – 用来将结果反射给一个实例化好的类的构造器    a ...

  2. LocalDate和LocalTime的用法介绍

    原文:LocalDate和LocalTime的用法介绍 在JAVA中,常用的处理日期和时间的类主要有Date,Calendar,而在JDK1.8中,新增了两个处理日期和时间的类,一个是LocalDat ...

  3. script放在body和放在head的区别

    放在body中:在页面加载的时候被执行 放在head中:在被调用时被执行 原因: 1.浏览器是从上到下解析HTML的. 2.放在head里的js代码,会在body解析之前被解析:放在body里的js代 ...

  4. JS 获取随机颜色值

    获取随机颜色值 function fn1(){ return '#' + Math.floor( Math.random() * 0xffffff ).toString(16); } function ...

  5. DOM盒模型和位置 client offset scroll 和滚动的关系

    DOM盒模型和位置 client offset scroll 和滚动的关系 概览 在dom里面有几个描述盒子位置信息的值, pading border margin width height clie ...

  6. 矩阵快速幂+二分 poj3233

    #include <iostream> #include <cstdio> #include <string> #include <cstring> # ...

  7. windows系统 安装 mysql.fx

    windows系统 安装 mqtt.fx 软件官网:http://mqttfx.jfx4ee.org/ 软件下载:http://www.jensd.de/apps/mqttfx/1.1.0/

  8. get_class和get_called_class的区别

    get_class ()       获取当前调用方法的类名get_called_class()    获取静态绑定后的类名 class Foo{ public function test() { v ...

  9. pocketsphinx实现连续大词汇量语音识别

    之前有个项目需求是要在客户内网实现一个连续大词汇语音识别功能,由于客户的内网是独立的,不能访问互联网,所以我只能到开源社区去找找碰碰运气了.后来在网上找到了cmusphinx(地址:http://cm ...

  10. SpringMVC开发RESTful接口

    概念: 什么是REST? REST是Representational State Transfer的缩写.翻译为"表现层状态转化",restful是一种接口设计风格,它不是一个协议 ...