Codeforces Round #464 (Div. 2) E. Maximize!

全网首发:香橙派5MAX安装ubuntu20.04(换了官方桌面)及ros,运行LIVOX-mid360混合固态激光雷达,实际测试fastlio(只能说可以跑,还是有点吃力) 独家发布!!!香橙派5MAX安装ubuntu20.04(换了官方桌面)及ros,运行mid360混合固态激光雷达,测试fastlio(只能说可以跑,还是有点吃力),国货也算崛起了。 阅读详情

You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries:

  1. Add a positive integer to S, the newly added integer is not less than any number in it.
  2. Find a subset s of the set S such that the value  is maximum possible. Here max(s) means maximum value of elements in s,  — the average value of numbers in s. Output this maximum possible value of .
Input

The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries.

Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given.

It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes.

Output

Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line.

Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .

Examples
input
Copy
6
1 3
2
1 4
2
1 8
2
output
0.0000000000
0.5000000000
3.0000000000
input
Copy
4
1 1
1 4
1 5
2
output
2.0000000000


题意:有一个多重集合(元素可以重复的),初始为空,现有两种操作,1是往集合里添加一个数字x,x一定不小于集合里的任何一个数(这个很重要),2是问这个集合子集中的 max(s) - mean(s)中最大的是多少,max(s)是一个集合中最大的元素,mean(s)是集合的平均值。

思路:因为这个集合是从小到大往里面加数的,很显然答案是这个多重集合中的最大值加上最前面一些数的和,那么加到什么位置为止呢?有这么一句话:如果一个数小于一些数的平均数,那么加上这个数,平均数会变小(我自己编的)。那么显然就有这样一个关系,设前面那些数的和为sum,数量为cnt个,现在集合中有n个数,那么答案就是 a[n] - (sum + a[n] )/ (cnt+1),那么这个sum怎么算呢,根据前面的结论:sum中已经有cnt个数了,如果  a[cnt+1] < (sum + a[n]) / (cnt+1),就可以把a[cnt+1]加到sum里,直到a[cnt+1]不符合条件为止。

好了啰嗦了这么多,其实代码很简单。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long

using namespace std;

LL a[500010];

int main(void)
{
    int q,i,j;
    while(scanf("%d",&q)==1)
    {
        LL sum = 0;
        int n = 0;
        int cnt = 0;
        while(q--)
        {
            int op,x;
            scanf("%d",&op);
            if(op == 1)
            {
                n++;
                scanf("%d",&a[n]);
                while(cnt < n && sum + a[n] > a[cnt+1]*(cnt+1))
                {
                    cnt++;
                    sum += a[cnt];
                }
            }
            else
            {
                double ans = a[n] - 1.0*(sum + a[n])/(cnt+1);
                printf("%.6f\n",ans);
            }
        }
    }


    return 0;
}

MTK_android11_WIFI(内网)和4G(外网)共存 阅读详情

相关推荐

rv1126 SDK编译【2020-0912版本SDK包】

rv1126 sdk 编译

学习记录 1万+

Maximize!(三分)

You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1:Add a positive integer to S, the newly added integer is not less than any number in it. 2...

yangzijiangac的博客 614

实战教程:如何用Python+小波变换+CNN搞定医学影像中的条纹噪声(附完整代码)

本文提供了一套完整的实战方案,指导如何利用Python结合小波变换与卷积神经网络(CNN)去除医学影像中的条纹噪声。该方法通过小波变换精准定位噪声,再使用轻量化CNN进行针对性清除,有效保护图像细节,并附有可运行的完整代码,为医学影像处理与AI分析提供高效工具。

weixin_29056101的博客 269

Maximize! CodeForces - 939E(三分,尺取)

You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a positive integer to S, the newly added integer is not less than any number in it. Fin...

tomjobs的博客 709

IGV新手必看:5分钟搞定ChIP-seq/DAP-seq/ATAC-seq数据可视化(附常见报错解决方案)

本文为IGV新手提供了一份快速上手的实战指南,详细讲解了如何高效完成ChIP-seq、DAP-seq、ATAC-seq等数据的可视化。内容涵盖软件安装、基因组导入、文件格式转换与优化,并重点剖析了“导入后一片空白”等常见报错的根本原因与解决方案,帮助用户在5分钟内避开雷区,生成可用于发表的IGV专业图谱。

weixin_29198045的博客 539

HIC测序数据生信分析——第三节,HIC数据挂载

(取决于是否运行①prune模块,若①运行,则③运行;#HIC预处理后的比对文件Unknown_BM942-001H0001_1_val_1.Unknown_BM942-001H0001_2_val_2.hicup.bam 和contig基因组序列文件genome.fa。#HIC预处理后的比对文件Unknown_BM942-001H0001_1_val_1.Unknown_BM942-001H0001_2_val_2.hicup.bam 和contig基因组序列文件genome.fa。#这个方法简单一点。

weixin_44616693的博客 3595

Codeforces 939 E Maximize!

题目描述 You are given a multisetSconsisting of positive integers (initially empty). There are two kind of queries: Add a positive integer toS, the newly added integer is not less than any number ...

weixin_30748995的博客 159

PID不够用?试试给PID加上‘预言’能力:史密斯预测器(SP)在温控、液位控制中的实战配置

本文深入探讨了史密斯预测器(SP)在温控和液位控制中的应用,特别针对大滞后系统的PID控制难题。通过详细解析SP的核心组件、参数整定技巧及进阶应用FSP,结合西门子PLC的实战配置方案,帮助工程师有效提升控制精度和系统稳定性。文章还提供了S7-1200的完整实现步骤和调试技巧,为工业自动化控制提供了实用解决方案。

weixin_33686714的博客 469

Codeforces 939E Maximize! (三分查找)

E. Maximize! time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given a multiset S consisting of posit

咸鱼有梦想 1151

AttributeError: module ‘lib‘ has no attribute ‘X509_V_FLAG_CB_ISSUER_CHECK‘解决方案

本文主要介绍了AttributeError: module ‘lib’ has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK’解决方案,希望能对使用python的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 5万+

【OpenClaw从入门到精通】第23篇:OpenClaw办公自动化实战—报表生成+文档批量处理+跨系统同步(2026实操进阶版)

本文聚焦OpenClaw在办公自动化场景的进阶应用,针对职场中高频且重复的报表生成、文档批量处理、跨系统数据同步三大痛点,提供从环境搭建、原理讲解到完整代码实现的全流程实操指南。方案基于Python生态工具链(pandas、Playwright、PyPDF2等)与OpenClaw的低代码编排能力,兼顾新手入门与进阶提升——新手可直接复用代码快速落地,进阶读者可学习流程编排逻辑进行二次开发。所有案例均基于真实办公场景设计,部分虚拟场景已明确标注,代码经本地环境验证可复现。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 968

codeforce 939D. Love Rescue(dfs+贪心)

D. Love Rescuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took ...

gyr 518

2021-09-29 每天几个LCEDA小知识——如何交叉选择并阵列放置元器件

立创EDA专业版之交叉选择并阵列放置元器件????交叉选择????阵列放置 ????交叉选择 在原理图界面,先框选需要交叉选择的元器件对象,右键,选择交叉选择(如果熟练之后,直接选择元器件,快捷键Shift+X)。 完成上述操作之后,可以看到自动跳转到PCB绘图界面,并自动选定PCB中相关的元器件,接下来不要取消选择的状态,在相关元器件被选中的情况下,即可开展阵列放置,将这些元器件都放在一个区域,方便PCB画线前的布局工作。 ????阵列放置 在布局菜单栏中,选择分布,选择阵列分布, 在弹出的对话框

l64481000的博客 1465

Codeforces Round #464 (Div. 2)E - Maximize!

二分求值,每次看了题解总感觉没难度,自己做酒做的很慢,还总是错,,#include&lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; typedef pair&lt;int, int&gt; pii; typedef long double ld; #define F first #define S second ...

但求心安的博客 294

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces Round #464 (Div. 2)E. Maximize!

题目题意:两种操作:1,代表输入一个数,每次输入的数不小于前面输入的数;2,代表输出max(s)-mex(s),在数组中找出子集,使子集的最大值减去子集平均值,,求出最大的值。方法:每次必选最大值,然后从小选取求平均值,判断,因为一个数比平均值小,加进来只会使平均值变小,比平均值变大,加进来会使平均值变大,所以可以三分#include &lt;cstdio&gt; #include&lt;iost...

hl_1997的博客 182

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

【CodeForces】CodeForces Round #464 (Div. 2) 题解

【比赛链接】点击打开链接【题解链接】点击打开链接【A】Love Triangle【思路要点】按照题意寻找三角形即可。即若存在一个点\(i\)使得\(f[f[f[i]]]==i\),答案为Yes,否则为No。时间复杂度\(O(N)\)。【代码】#include&lt;bits/stdc++.h&gt; using namespace std; const int MAXN = 5005; templ...

cz_xuyixuan的博客 1239

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Codeforces Round #464 (Div. 2)-E-Maximize!(二分or三分)

题意:给你一个初始为空的集合,每次有两种操作:(1)将集合中添加一个新数,这个数保证不小于集合中任何一个数(2)你选择已有集合的一个子集,使得该集合最大的元素-(该集合所有元素的平均值)的值最大题解:首先一个结论是最大的呢个数一定要加上,因为其他数都比它小,所以会减弱它对平均值的贡献的基础上又能保证最大值尽可能大,之后你要知道,你选的这个集合除了最大的呢个数,其他元素一定是连续的,如果你隔一个小的...

信仰.的博客 406

Codeforces 939E Maximize! 尺取法/贪心

E. Maximize!time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a multiset S consisting of positive integers (initially empty). There ar...

J. Cole 442

codeforce 939 E. Maximize!(贪心)

E. Maximize!time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a multiset S consisting of positive integers (initially empty). There ar...

gyr 382

Codeforces 939E - Maximize! 三分

http://codeforces.com/problemset/problem/939/E 题目: E. Maximize! time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given a...

sun_hongjia的博客 763

Codeforces Round #464 (Div. 2) D. Love Rescue

Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullove...

SSimpLe_Y的博客 1388

codefoces 939E Maximize!好题

题解 若存在一个子集s满足答案的话,则该子集一定包含集合S的最大值。 反证法证明: 假设s集合中最大的元素为x,S集合中最大的元素为X。则如果把x换成X,最大值增加了X-x,而平均值增量一定不大于X-x。 这样的话,确定了最大值,s中剩下的数一定从集合S中从小到大依次选取, 而存在一个事实:我们通过不断向集合s中添加元素,集合s的平均值会先减小,后增大。 这个...

SUNSET 425

CF Round #464 (Div. 2) E. Maximize! (尺取或三分)

Link http://codeforces.com/contest/939/problem/E Description Problem Statement You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a posi...

梧桐 322
上一篇: Codeforces Round #464 (Div. 2) D. Love Rescue
下一篇: Codeforces Round #466 (Div. 2) E. Cashback (dp+树状数组+RMQ)
SSimpLe_Y
博客等级 码龄10年 89粉丝 181原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值