Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization
题目链接
http://codeforces.com/contest/735/problem/B
题面
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 people. Of course, each of n candidates can settle in only one of the cities. Thus, first some subset of candidates of size n1 settle in the first city and then some subset of size n2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.
To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth ai among all its residents divided by the number of them (n1 or n2 depending on the city). The division should be done in real numbers without any rounding.
Please, help authorities find the optimal way to pick residents for two cities.
输入
The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), the i-th of them is equal to the wealth of the i-th candidate.
输出
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .
样例输入
2 1 1
1 5
样例输出
6.00000000
题意
一共有n个数,第i个数是a[i],现在你需要选出n1个数和n2个数,使得那n1个数的和除以n1加上n2个数的和除以n2的值最大。
题解
贪心,如果n1>n2,那么交换
然后选择最大的n1个数为n1集合,然后次大的n2个数为n2集合。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,n1,n2,nn1,nn2;
double a[maxn];
int main()
{
scanf("%d%d%d",&n,&n1,&n2);
if(n1>n2)swap(n1,n2);
nn1=n1,nn2=n2;
for(int i=0;i<n;i++)
scanf("%lf",&a[i]);
sort(a,a+n);
reverse(a,a+n);
double sum1=0,sum2=0;
for(int i=0;i<n;i++){
if(n1){
sum1+=a[i];
n1--;
}else if(n2){
sum2+=a[i];
n2--;
}
}
double ans = (sum1/nn1)+(sum2/nn2);
printf("%.12f\n",ans);
}
Codeforces Round #382 (Div. 2)B. Urbanization 贪心的更多相关文章
- Codeforces Round #202 (Div. 1) A. Mafia 贪心
A. Mafia Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...
- Codeforces Round #382 (Div. 2) 继续python作死 含树形DP
A - Ostap and Grasshopper zz题能不能跳到 每次只能跳K步 不能跳到# 问能不能T-G 随便跳跳就可以了 第一次居然跳越界0.0 傻子哦 WA1 n,k = map ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- Codeforces Round #180 (Div. 2) B. Sail 贪心
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...
随机推荐
- wsdl地址如何在远程服务器上查看源码?
工作需要,接了几个webservice接口,但是厂家给的规范十分不规范,服务名称没一个写对的,要是我的本地电脑可以打开wsdl地址,那倒没什么,察看一下wsdl就可以. 但是好多wsdl地址我本地电脑 ...
- 【12_206】Reverse Linked List
本来没想出来,刚才突然想到,可以用“头插法”来反转 Reverse Linked List My Submissions Question Total Accepted: 66556 Total Su ...
- Nginx代理与负载均衡配置与优化
Nginx代理 Nginx从0.7.48版本开始,支持了类似Squid的缓存功能.Nginx的Web缓存服务主要由proxy_cache相关指令集和fastcgi_cache相关指令集构成,前者用于反 ...
- 工具武装的前端开发工程师 Mac 软件清单
Awesome Mac 这个仓库主要是收集非常好用的Mac应用程序.软件以及工具,主要面向开发者和设计师.有这个想法是因为我最近发了一篇较为火爆的涨粉儿微信公众号文章<工具武装的前端开发工程 ...
- 笔记:Hyper-V上Centos 6.5分辨率调整问题解决笔记
最近忙的没有心情写东西,果然博客就这么长草了.今天就稍微写一点点东西吧,反正这问题挺烦的. 背景如下:为准备做redis集群实验,特在笔记本上搭建CentOS6.5的Hyper-V虚拟机. 虚拟机创建 ...
- SQLSERVER 数据库性能的的基本
SQLSERVER 数据库性能的基本 很久没有写文章了,在系统正式上线之前,DBA一般都要测试一下服务器的性能 比如你有很多的服务器,有些做web服务器,有些做缓存服务器,有些做文件服务器,有些做数据 ...
- 尝试在mac上用dotnet cli运行asp.net core示例程序
自从知道微软用dotnet cli取代dnx之后,一直在等dotnet cli支持asp.net core... 昨天看到这篇新闻(ASP.NET Core 1.0 Hello World)后,才知道 ...
- 在 .NET 4.5 中反射机制的变更
反射机制(Reflection)通常会涉及到3中场景: 运行时反射 场景:可以检索已加载程序集.类型.对象.实例和方法调用的元数据(Metadata). .NET 支持情况:支持 仅供静态分析的反射 ...
- phpMyAdmin导入文件突破2M大小
一:通过phpinfo.php找到php.ini在哪个位置,注意,它并不一定在phpMyAdmin路径下: 二:修改upload_max_filesize,post_max_size,以及memory ...
- 第八章xml学习
1.ASP.NET和JSP的关系 ASP.NET 和JSP都是用来开发动态网站的技术,只不过ASP.NET是通过c#语言来操作的, 而JSP是通过Java语言来操作的. 2.为什么学习XML? 01. ...