Codeforces 735B - Urbanization
思路:贪心。人数少的城市住钱最多的那几个人。
不证明了,举个例子吧:a1<a2<a3<a4<a5
(a1+a2+a3)/3+(a4+a5)/2==(2*a1+2*a2+2*a3+3*a4+3*a5)/6①
(a1+a2)/2+(a3+a4+a5)/3==(3*a1+3*a2+2*a3+2*a4+2*a5)/6 ②
因为a4+a5>a1+a2所以①式大于②式,同理可证其他方案都比①式小。
本质就是分母通分后都一样,在分子中把最大的分母和最大的钱数相乘,使得最大的钱数的权值也最大。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+;
int a[N];
bool cmp(int &a,int &b)
{
return a>b;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,n1,n2;
cin>>n>>n1>>n2;
for(int i=;i<n;i++)cin>>a[i]; sort(a,a+n,cmp);
if(n1>n2)swap(n1,n2);
int c=,t1=n1,t2=n2;
double sum1=,sum2=;
while(n1)
{
sum1+=a[c];
c++;
n1--;
}
while(n2)
{
sum2+=a[c];
c++;
n2--;
}
cout<<fixed<<setprecision()<<sum1/t1+sum2/t2<<endl;
return ;
}
Codeforces 735B - Urbanization的更多相关文章
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- 【50.88%】【Codeforces round 382B】Urbanization
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- POST—常见的4种提交方式
HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中,POST 一般用来向服务端提交数据,本文 ...
- shell篇(二)
Linux的shell种类比较多,常见的有:Bourne Shell(/user/bin/sh或者/bin/sh), Bourne Again Shell(/user/bin/bash或者/bin/b ...
- 绘制loss曲线
第一步保存日志文件,用重定向即可: $TOOLS/caffe train --solver=$SOLVERFILE >& |tee out.log 第二步直接绘制: python plo ...
- python 单例模式,一个类只能生成唯一的一个实例,重写__new__方法详解
单例:一个类只能生成唯一的一个实例 每个类只要被实例化了,他的私有属性 '_instance'就会被赋值,这样理解对吗 对 #方法1,实现__new__方法 #并在将一个类的实例绑定到类变量_inst ...
- WordPress存在DoS拒绝服务漏洞,推荐删除根目录下的xmlrpc.php
WordPress存在DoS拒绝服务漏洞,推荐删除根目录下的xmlrpc.php受影响的版本:WordPress 3.9.x-3.9.1WordPress 3.8.x-3.8.3WordPress 3 ...
- TED #08# Learn to read Chinese ... with ease!
ShaoLan: Learn to read Chinese ... with ease! Pre-requisites calligraphermy most treasured memoriesw ...
- bzoj1641 / P2888 [USACO07NOV]牛栏Cow Hurdles
P2888 [USACO07NOV]牛栏Cow Hurdles Floyd $n<=300$?果断Floyd 给出核心式,自行体会 $d[i][j]=min(d[i][j],max(d[i][k ...
- Java ftp上传文件方法效率对比
Java ftp上传文件方法效率对比 一.功能简介: txt文件采用ftp方式从windows传输到Linux系统: 二.ftp实现方法 (1)方法一:采用二进制流传输,设置缓冲区,速度快,50M的t ...
- 静态编译C/C++程序
静态编译C/C++程序,让程序运行不受平台限制 由于Linux操作系统的特有elf加载顺序. (可以参考此文). 虽然可以很大程度上解决Windows早期版本的dll hell问题, 但是给部署带来了 ...
- 使用openssl生成SSL证书完全参考手册
一般来说,配置HTTPS/SSL的步骤为: 1.生成足够强度的私钥.需要考虑:算法,广泛采用的一般是RSA.键长度,RSA默认为512,一般应选择2048.密码,虽然私钥不一定要加密存储,但是加密存储 ...