Codeforces Round #382 (Div. 2)B. Urbanization 贪心
来源:互联网 发布:鲁滨逊漂流记游戏java 编辑:程序博客网 时间:2024/06/01 20:06
题目链接:这里
题意:一共有n个数,第i个数是a[i],现在你需要选出n1个数和n2个数,使得那n1个数的和除以n1加上n2个数的和除以n2的值最大。
解法:贪心,如果n1>n2,那么交换。然后选择最大的n1个数为n1集合,然后次大的n2个数为n2集合。
代码:
//CF 735B#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+7;int n, n1, n2, nn1, nn2;double a[maxn];int main(){ cin >> n >> n1 >> n2; for(int i = 0; i < n; i++) cin >> a[i]; if(n1 > n2) swap(n1, n2); nn1 = n1, nn2 = n2; sort(a, a+n, greater<double>()); 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/(1.0*nn1)) + (sum2/(1.0*nn2)); printf("%.10f\n", ans); return 0;}
0 0
- Codeforces Round #382 (Div. 2) B. Urbanization(贪心)
- Codeforces Round #382 (Div. 2)-735B. Urbanization(贪心)
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
- Codeforces#382(Div. 2) B.Urbanization【贪心】
- Codeforces Round #382 (Div. 2) B. Urbanization
- Codeforces Round #382 (Div. 2) B. Urbanization
- Codeforces Round #382 (Div. 2) B. Urbanization【数据注意+贪心证明】
- Codeforces Round #382 (Div. 2) 735B - Urbanization
- Codeforces Round #382 (Div. 2) 735B Urbanization
- 【50.88%】【Codeforces round 382B】Urbanization
- Codeforces Round #382 (Div. 2)A到D题 A. Ostap and //B. Urbanization//C. Tennis Championship//D. Taxes
- CodeForces 735B - Urbanization(贪心)
- Codeforces 735B - Urbanization 贪心
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #428 (Div. 2) B 贪心
- codeforces - 735B - Urbanization(贪心)
- CodeForces 735 B.Urbanization(贪心)
- Codeforces Round #109 (Div. 2) B (贪心)
- 前端页面性能参数搜集
- nyoj499 迷宫
- (0028)iOS 开发之Xcode使用技巧
- Linux 简单 git 使用教程
- 单片机的学习
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
- springMVC应用程序执行流程
- 前端性能优化的另一种方式——HTTP2.0
- 广义拉格朗日函数的理解(可用于SVM推导)
- 对于java关键字volatile,和transient 的理解
- WebWork
- 为你的网站添加触控,实现自定义手势
- hdu 5317 RGCDQ
- Swift3.0 / swift2.3中dispatch_group的使用