CF-1111B-Average Superhero Gang Power

首先,对于这题我们要知道要删除一个数使平均值最大一定是删除最小的数,然后我们假设删除操作执行了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 + 5;
int arr[MAXN];
double ans;
int main() {
    int n, k, m;
    scanf("%d%d%d", &n, &k, &m);
    LL sum = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
        sum += arr[i];
    }
    sort(arr + 1, arr + 1 + n);
    for (int i = 0; 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 0;
}

原文地址:https://www.cnblogs.com/Angel-Demon/p/10353999.html

时间: 2024-11-02 17:04:54

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

CF w1d2 B. Average Superhero Gang Power

Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are n superheroes in avengers team havin

CodeCraft-19 and Codeforces Round #537 (Div. 2) B. Average Superhero Gang Power

题目描述: Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are nn superheroes in avengers tea

CF w1d2 A. Superhero Transformation

Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are n superheroes in avengers team havin

CodeCraft-19 and Codeforces Round #537 (Div. 2)

A. Superhero Transformation 水题,注意两个字符串可能长度不相等. #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; const int maxn=100010; map<char ,int >m; int main(){ m['a']=m['e']=m['i']=m['o']=m['u']=1;

codeforces contest 1111

A. Superhero Transformation 题意: 元音和元音,辅音和辅音字母之间可以互相转换,问两个字符串是否想同: 题解:直接判断即可: 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1010; 4 char s[N]; 5 int n,m,vis1[N],vis2[N]; 6 int judge(char x){return x=='a'||x=='e'||x=='i'||x=='o'||x=='

Python与rrdtool的结合模块

rrdtool(round robin database)工具为环状数据库的存储格式,round robin是一种处理定量数据以及当前元素指针的技术.rrdtool主要用来跟踪对象的变化情况,生成这些变化的走势图,比如业务的访问流量.系统性能.磁盘利用率等趋势图,很多流行监控平台都使用到rrdtool,比较有名的为Cacti.Ganglia.Monitorix等.更多rrdtool介绍见官网http://oss.oetiker.ch/rrdtool/.rrdtool是一个复杂的工具,涉及较多参数

[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 compiler with Typescript type assertion. We have a SuperHero and a BadGuy. Let's make a function that saves the day if the function's argument is a Sup

Display controller

Field of the Invention The present invention relates to a display controller. Background to the invention Display controllers are known. One such display controller 10 is shown in the display system, generally 5, illustrated by figure 1. A display 40

Pyhton模块学习

rrdtool: rrdtool可直接用pip install python-rrdtool import rrdtool 创建:create(...)create(args..): Set up a new Round Robin Database create filename [--start|-b start time] [--step|-s step] [DS:ds-name:DST:heartbeat:min:max] [RRA:CF:xff:steps:rows] filename