首先,对于这题我们要知道要删除一个数使平均值最大一定是删除最小的数,然后我们假设删除操作执行了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. c语言的各种技巧

    一.参考网址 1.参考网址1:C 语言的奇技淫巧 二.

  2. 手机H5,用Jquery使图片自动填满两栏式排版

    遇上这样的排版,手机的解象度都不同,假如只用CSS3根本就做不出这样的排版:因此要用Jquery. 1. HTML <div class="postImgCenterCrop" ...

  3. JAVA初学者——逻辑运算符

    Hello!大家好,我是浩宇大熊猫~ 加油~充实每一天~ java里面的逻辑运算符有与(&).或(|).异或(^).非(!) 其实这些初高中数学课都学过哈,很简单~ public class ...

  4. idhttp文件的上传和下载

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  5. header() 被用来发送自定义的 HTTP 报文

    header() 被用来发送自定义的 HTTP 报文.关于HTTP报文的更多信息请参考» HTTP/1.1 specification. 请注意一点header()必须在任何实际输出之前调用,不管是普 ...

  6. Codeforce 370A Rook, Bishop and King 数学规律

    这个题目挺有意思的,给定 起终点,要你求车,象,王分别最少要走多少步 车横竖都能走,而且每步任意走几格,所以它是最容易处理的,如果在同行或者同列,就是1,否则就是2 象要找下规律,象任意对角线都能走, ...

  7. liunx 常用操作(自用)

    Centos7解压文件 tar -zxvf 文件名[test.tar.gz] Centos7安装vim yum -y install vim* Centos7安装ifconfig yum instal ...

  8. Salt常用命令二

    ############################模块############################ 查看模块列表——module salt ‘minion’  sys.list_mo ...

  9. epoll——IO多路复用选择器

    上上篇博客讲的套接字,由于其阻塞性而导致一个服务端同一时间只能与一个客户端连接.基于这个缺点,在上篇博客我们将其设置为非阻塞实现了一个服务端同一时间可以与多个客户端相连,即实现了并发,但其同样留下了一 ...

  10. 安装chrome并设置默认主页

    chrome 版本 https://support.google.com/chrome/a/answer/187948?hl=en&ref_topic=2936229