首先,对于这题我们要知道要删除一个数使平均值最大一定是删除最小的数,然后我们假设删除操作执行了i次,也就是删除最小的i个数。在已知删除操作次数之后求增加操作的次数就容易了,当然是m - i和k * (n - i)中比较小的数啦。用一个ans变量记录结果,遍历i,更新ans,得到最终的ans。

B - Average Superhero Gang Power GNU C++11 Accepted 46 ms 400 KB
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + ;
int arr[MAXN];
double ans;
int main() {
int n, k, m;
scanf("%d%d%d", &n, &k, &m);
LL sum = ;
for (int i = ; i <= n; i++) {
scanf("%d", &arr[i]);
sum += arr[i];
}
sort(arr + , arr + + n);
for (int i = ; i < n && i <= m; i++) {
sum -= arr[i];
// min和max函数要求两个参数数据类型相同,k * (n - i)可能爆int,所以两边都转成LL;
ans = max(ans, (sum + min(1LL * m - i, 1LL * k * (n - i))) * 1.0 / (n - i));
}
printf("%.8lf", ans);
return ;
}

CF-1111B-Average Superhero Gang Power的更多相关文章

  1. 1111B - Average Superhero Gang Power

    刷数学题不知道为啥出来这个 算是贪心吧,先把所有的power加起来,然后sort一遍,每次删掉最小的那个数,记录一个max,平均值ave如果比max大,就替换,一定要小心m的值可能会比n小,意味着不一 ...

  2. CF 1005C Summarize to the Power of Two 【hash/STL-map】

    A sequence a1,a2,-,an is called good if, for each element ai, there exists an element aj (i≠j) such ...

  3. codeforces contest 1111

    A. Superhero Transformation 题意: 元音和元音,辅音和辅音字母之间可以互相转换,问两个字符串是否想同: 题解:直接判断即可: #include<bits/stdc++ ...

  4. CF-1111 (2019/2/7 补)

    CF-1111 题目链接 A. Superhero Transformation tags : strings #include <bits/stdc++.h> using namespa ...

  5. python3 rrdtool 使用

    源自 python自动化运维:技术与最佳实践 并做略微修改 安装 yum install python-rrdtoolyum install rrdtool-devel #因为采集用了psutil模块 ...

  6. Daily record-August

    August11. A guide dog can guide a blind person. 导盲犬能给盲人引路.2. A guide dog is a dog especially trained ...

  7. Python与rrdtool的结合模块

    rrdtool(round robin database)工具为环状数据库的存储格式,round robin是一种处理定量数据以及当前元素指针的技术.rrdtool主要用来跟踪对象的变化情况,生成这些 ...

  8. AVAudioFoundation(4):音视频录制

    本文转自:AVAudioFoundation(4):音视频录制 | www.samirchen.com 本文主要内容来自 AVFoundation Programming Guide. 采集设备的音视 ...

  9. [TypeScript] Using Assertion to Convert Types in TypeScript

    Sometimes the compiler needs help figuring out a type. In this lesson we learn how to help out the c ...

随机推荐

  1. Java - 记录String中intern()方法的学习与理解

    intern()方法:把堆中的引用丢入常量池中,然后返回这个引用.当常量池中已经存在这个引用,就直接返回这个引用.(jdk1.8) 由于jdk1.7中将字符串常量池改为存放在堆中,因此intern() ...

  2. POJ 1655 Balancing Act【树的重心模板题】

    传送门:http://poj.org/problem?id=1655 题意:有T组数据,求出每组数据所构成的树的重心,输出这个树的重心的编号,并且输出重心删除后得到的最大子树的节点个数,如果个数相同, ...

  3. not in 优化 NOT EXISTS替代

    优化前 SELECT id, loan_id, NAME FROM xw_baoxian_interchange WHERE , , ) , ) AND loan_id NOT IN ( SELECT ...

  4. 吴裕雄--天生自然 JAVA开发学习:方法

    /** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) re ...

  5. Python 中 JSON和dict的转换,json的使用

    一. 基础语法 在Python 的 json库中,共有四个方法.分别是: json.load() # 从文件中加载 json.loads() # 数据中加载 json.dump() # 转存到文件 j ...

  6. ZJNU 1310 - 排队——中高级

    蒟蒻做法:追踪1号队员,取他回到原来位置需要的次数 /* Written By StelaYuri */ #include<stdio.h> int main(){ int T,t,n,a ...

  7. UI Automation编程辅助工具Inspect的下载和使用

    UIAutomation微软提供的UI自动化库,主要用AutomationElement类来表示UI 自动化目录树中的一个UI自动化元素,.NET Windows的窗体应用程序和WPF应用程序. In ...

  8. 添加头文件的报错failed to emit precompiled header 的解决办法

    在buildsetting中的以下两个路径中添加对应的设置,重现编译即可解决,stackoverflow地址:点击 Solution:1 I added $(inherited) non-recurs ...

  9. 基于JWT的Token认证机制及安全问题

    [干货分享]基于JWT的Token认证机制及安全问题 https://bbs.huaweicloud.com/blogs/06607ea7b53211e7b8317ca23e93a891

  10. IntelliJ IDEA 2019.2.2在16GB内存下的性能调优

    开发工具 IntelliJ IDEA 2019.2.2 x64 idea64.exe.vmoptions -m -m -XX:ReservedCodeCacheSize=m -XX:+UseConcM ...