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 ...
随机推荐
- Leetcode: Construct Binary Tree from Preorder and Inorder Transversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...
- ef延迟加载不到导航属性问题
最近做项目踩到了一个ef问题上的坑,导航属性(外键关键,如子表或主表等)“.”出来后是Null,外键值也对,数据库和ef的关系配置也都正确,就是加载不出来.后来发现实体里导航属性前少了个virtual ...
- linux常用命令:wc 命令
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 1.命令格式: wc [选项]文件... 2.命令功能: 统计指定文件中的字节数. ...
- Javassist
Javassist 实现动态代理 javassist 是一款非常优秀的Java 字节码引擎工具,能够在运行时编译.生成Java Class.
- linux服务器---安装samba
安装samba 1.检测samba是否安装,如果没有,那么可以使用yum来安装.至少需要安装3个软件:samba,samba-client.samba-common [root@localhost p ...
- SpringBoot之集成WebSocket
websocket是什么不做介绍.开发环境:jdk1.8,win7_64旗舰版,idea 1.初始化一个springboot项目 2.加入websocket依赖 <!-- springb ...
- Nginx启动SSL功能
Nginx启动SSL功能,并进行功能优化,你看这个就足够了 一:开始Nginx的SSL模块 1.1 Nginx如果未开启SSL模块,配置Https时提示错误 nginx: [emerg] the &q ...
- Linux(CentOS)下同时启动两个tomcat
问题背景:在配置nginx时,配置了两个tomcat,tomcat01和tomcat02,改了tomcat02中server.xml的端口,可是还是启动不起来. 解决方法: 一.编辑环境变量: 1 v ...
- PHP二维数组排序(感谢滔哥lvtao.net)
滔哥原创 /* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\|| ...
- Python3.x:抓取百事糗科段子
Python3.x:抓取百事糗科段子 实现代码: #Python3.6 获取糗事百科的段子 import urllib.request #导入各类要用到的包 import urllib import ...