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的更多相关文章

  1. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  2. 【50.88%】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. yii2增删改查及AR的理解

    yii2增删改查 // 返回 id 为 1 的客户 $customer = Customer::findOne(1); // 返回 id 为 1 且状态为 *active* 的客户 $customer ...

  2. python练习题-写一个函数,打印所有包含copy方法的内置对象

    代码: #encoding=utf-8for i in dir(__builtins__):    #print "i:",i    try: #这里的i是个字符串,并不能直接用d ...

  3. Node.js最新技术栈之Promise篇

    前言 大家好,我是桑世龙,github和cnodejs上的i5ting,目前在天津创业,公司目前使用技术主要是nodejs,算所谓的MEAN(mongodb + express + angular + ...

  4. adb shell 命令详解,android, adb logcat

    http://www.miui.com/article-275-1.html http://noobjava.iteye.com/blog/1914348 adb shell 命令详解,android ...

  5. 02: python3使用email和smtplib库发送邮件

    1.1 发送qq邮箱 注:python代理登录qq邮箱发邮件,是需要更改自己qq邮箱设置的.在这里大家需要做两件事情:邮箱开启SMTP功能 .获得授权码 教程链接 1.给单个人发邮件 参考 from ...

  6. 20145318《网络对抗》MSF基础应用

    20145318 <网络对抗> MSF基础应用 实验内容 掌握metasploit的基本应用方式,掌握常用的三种攻击方式的思路.具体需要完成(1)一个主动攻击,如ms08_067;(2)一 ...

  7. C++11标准 STL正则表达式 验证电子邮件地址

    转自:http://www.cnblogs.com/yejianfei/archive/2012/10/07/2713715.html 我们最经常遇到的验证,就是电子邮件地址验证.网站上常见.各种网页 ...

  8. 把一个activity作为弹窗

    1.可以在这个activity的xml中设置其高度为某个固定高度 2.在java中:getWindow().setGravity(Gravity.BOTTOM);//设置在底部出现  getWindo ...

  9. cogs 2221. [SDOI2016 Round1] 数字配对

    ★★ 输入文件:pair.in 输出文件:pair.out 简单对比 时间限制:1 s 内存限制:128 MB [题目描述] 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两 ...

  10. P1471 方差

    题目 luogu 思路 \[\frac{1}{n}*\sum_{1}^{n}( a_{i}-A)^{2}\] \[\frac{1}{n}*\sum_{1}^{n}( a_{i}^2-2*A*a_{i} ...