Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)

简介: Codeforces #737Div2A. A. Ezzat and Two Subsequences(模拟)

Ezzat has an array of n integers (maybe negative). He wants to split it into two non-empty subsequences a and b, such that every element from the array belongs to exactly one subsequence, and the value of f(a)+f(b) is the maximum possible value, where f(x) is the average of the subsequence x.


A sequence x is a subsequence of a sequence y if x can be obtained from y by deletion of several (possibly, zero or all) elements.


The average of a subsequence is the sum of the numbers of this subsequence divided by the size of the subsequence.


For example, the average of [1,5,6] is (1+5+6)/3=12/3=4, so f([1,5,6])=4.


Input

The first line contains a single integer t (1≤t≤103)— the number of test cases. Each test case consists of two lines.


The first line contains a single integer n (2≤n≤105).


The second line contains n integers a1,a2,…,an (−109≤ai≤109).


It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.


Output

For each test case, print a single value — the maximum value that Ezzat can achieve.


Your answer is considered correct if its absolute or relative error does not exceed 10−6.


Formally, let your answer be a, and the jury’s answer be b. Your answer is accepted if and only if |a−b|max(1,|b|)≤10−6.


样例输入


4

3

3 1 2

3

-7 -6 -6

3

2 2 2

4

17 3 5 -3


样例输出


4.500000000

-12.500000000

4.000000000

18.666666667


题意


将一个给定的数组分成两个数组,将每个数组的和除以这个数组的个数,将两个数相加。

找一个最合理的分配方式使相加后的和最大,输出这个最大的和;


这个简单,就是把最大的拿出来,加上前面的平均数;


如果有测试点2,超限的,提醒一下不要用double,在数组定义里面


听懂了记得给个赞鼓励一下,码字不易,用爱发电。


上ac代码。

f58230e9f063709cf3167704f4efdf14.gif


有事你就q我;QQ2917366383


学习算法

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin>>t;
  while(t--)
  {
  long long sum=0;int m;
    long long  c[100000];//这里如果用double会提示测试点2不能通过,甚至可能出现错误
  scanf("%d",&m);
    for(int i=1;i<=m;i++)
   scanf("%lld",&c[i]);
    sort(c+1,c+m+1);    
    for(int i=1;i<=m-1;i++)
    sum+=c[i];
printf("%.9f\n",(1.0*sum/(m-1)+c[m]));
  }
 } 


相关文章
|
SQL NoSQL 网络协议
高性能分布式No SQL数据库Aerospike(二)——安装部署
高性能分布式No SQL数据库Aerospike(二)——安装部署
1110 0
高性能分布式No SQL数据库Aerospike(二)——安装部署
|
弹性计算 Ubuntu 网络安全
借助阿里云ECS实现本地电脑连接实验室内网服务器
在实验室的服务器上进行开发,往往只能通过内网电脑进行ssh连接。然而疫情当下,很多时候都要居家办公,或远程办公。借助阿里云ECS,我们可以搭建一个FRP服务,实现内网穿透,在家里的电脑也可以ssh连接内网服务器。
1697 1
借助阿里云ECS实现本地电脑连接实验室内网服务器
|
10月前
|
供应链 安全 Cloud Native
阿里云飞天企业版获【可信云·容器平台安全能力】先进级认证
阿里云飞天企业版容器系列产品获中国信息通信研究院【可信云·容器平台安全能力】先进级认证,这是飞天企业版容器产品获得《等保四级PaaS平台》和《 云原生安全配置基线规范V2.0》之后,本年度再一次获得行业权威认可,证明飞天企业版的容器解决方案具备符合行业标准的最高等级容器安全能力。
309 8
阿里云飞天企业版获【可信云·容器平台安全能力】先进级认证
|
7月前
|
Python
Python中Cp、Cpk、Pp、Ppk的计算与应用
总的来说,Cp、Cpk、Pp、Ppk是衡量过程能力的重要工具,它们可以帮助我们了解和改进生产过程,提高产品质量。
664 13
|
11月前
|
缓存 负载均衡 算法
深入理解后端服务的负载均衡技术
在现代网络服务架构中,高效的负载均衡策略对于保证应用性能和可靠性至关重要。本文将深入探讨后端服务中的负载均衡技术,包括其重要性、常见算法以及如何实现高效均衡。通过分析不同的负载均衡方法,我们旨在为开发者提供实用的指导,帮助他们优化自己的系统架构。
|
数据可视化 数据处理 数据库
【Python篇】PyQt5 超详细教程——由入门到精通(中篇一)
【Python篇】PyQt5 超详细教程——由入门到精通(中篇一)
1098 2
|
存储 消息中间件 设计模式
计算机网络——应用层(1)
计算机网络——应用层(1)
Due to limitations of the com.mongodb.BasicDocument, you can‘t add a second ‘_id‘ criteria. Query al
Due to limitations of the com.mongodb.BasicDocument, you can‘t add a second ‘_id‘ criteria. Query al
375 2
|
XML JSON 缓存
Java实现订单ID获取淘宝买到的订单详情数据接口方法
Java实现订单ID获取淘宝买到的订单详情数据接口方法
|
机器学习/深度学习 PyTorch 语音技术
使用PyTorch构建卷积神经网络(CNN)源码(详细步骤讲解+注释版) 01 手写数字识别
在使用PyTorch构建GAN生成对抗网络一文中,我们使用GAN构建了一个可以生成人脸图像的模型。但尽管是较为简单的模型,仍占用了1G左右的GPU内存,因此需要探索更加节约资源的方式。

热门文章

最新文章