首先,对于这题我们要知道要删除一个数使平均值最大一定是删除最小的数,然后我们假设删除操作执行了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. CSS3-选中的锚链接改变指定样式

    1.css样式 主角就是:target <a> 标签的 target 属性规定在何处打开链接文档,连接文档也可以是一个样式. 如果在一个 <a> 标签内包含一个 target ...

  2. WINSCP 使用笔记

    前期准备: 1.官网下载:http://winscp.net/eng/docs/lang:chs 官网C#示例:http://winscp.net/eng/docs/library#csharp 当然 ...

  3. I420转RGB

    http://blog.csdn.net/huiguixian/article/details/17288909 public class YuvToRGB { private static int  ...

  4. PAT Advanced 1138 Postorder Traversal (25) [树的遍历,前序中序转后序]

    题目 Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and ...

  5. Random Access Iterator

    Random Access Iterator 树型概率DP dp[u]代表以当前点作为根得到正确结果的概率 将深度最深的几个点dp[u]很明显是1 然后很简单的转移 有k次,但我们要先看一次的情况,然 ...

  6. 实现文件上下文管理(\_\_enter\_\_和\_\_exit\_\_)

    实现文件上下文管理(__enter__和__exit__) 我们知道在操作文件对象的时候可以这么写 with open('a.txt') as f: '代码块' 上述叫做上下文管理协议,即with语句 ...

  7. python文件读写 文件修改

    #设置一个变量f为文件对象,并打开文件#写文件#f = open('user.txt','w',encoding='utf-8') #f是一个文件对象f=open(r'c:\Users\PL\Desk ...

  8. Python语言学习:字符串常用的方法

    python字符串常用的方法 1. find( ):在字符串中搜索指定的值并返回它被找到的位置,如果没有找到,则返回-1 string.find(value,start,end) #value:必需, ...

  9. 编译原理_P1002

    . 词法分析 1.1 词法记号及属性 词法记号.模式.词法单元 记号名 词法单元列举    模式的非形式描述 if if 字符i,f for for     字符f,o,r relation < ...

  10. 安卓ButtomBar实现方法

    这里ButtomBar有3个items,分别有icon和文字,在当前fragment时,所属的icon和文字会显示不同颜色. 1. 首先要准好ICON素材,命名规范要清楚. 2. 实现这个Buttom ...