NC17400 gpa

题目

题目描述

Kanade selected n courses in the university. The academic credit of the i-th course is s[i] and the score of the i-th course is c[i].

At the university where she attended, the final score of her is \(\frac{\sum s[i]c[i]}{\sum s[i]}\)

Now she can delete at most k courses and she want to know what the highest final score that can get.

输入描述

The first line has two positive integers n,k

The second line has n positive integers s[i]

The third line has n positive integers c[i]

输出描述

Output the highest final score, your answer is correct if and only if the absolute error with the standard answer is no more than \(10^{-5}\)

示例1

输入

3 1
1 2 3
3 2 1

输出

2.33333333333

说明

Delete the third course and the final score is \(\frac{2*2+3*1}{2+1}=\frac{7}{3}\)

备注:

\(1≤ n≤ 10^5\)

\(0≤ k < n\)

\(1≤ s[i],c[i] ≤ 10^3\)

题解

思路

知识点:01分数规划。

删去 \(k\) 个课程,那剩下取 \(n-k\) 个课程。答案的可行性函数符合单调性,且答案是唯一零点,于是二分答案,有如下公式:

\[\begin{aligned}
\frac{\sum s[i]c[i]}{\sum s[i]} &\geq mid\\
\sum (s[i]c[i] - mid \cdot s[i]) &\geq 0
\end{aligned}
\]

因此每次检验对 \(s[i]c[i]-mid\cdot s[i]\) 从大到小排序,取前 \(n-k\) 个加和,观察是否满足不等式,来决定舍弃区间。

注意精度开大一次方。

时间复杂度 \(O(n \log n + k)\)

空间复杂度 \(O(n)\)

代码

#include <bits/stdc++.h>

using namespace std;

double s[100007], c[100007], sc[100007];
int n, k; bool check(double mid) {
for (int i = 0;i < n;i++) sc[i] = s[i] * c[i] - mid * s[i];
sort(sc, sc + n, [&](double a, double b) {return a > b;});
double sum = 0;
for (int i = 0;i < n - k;i++) sum += sc[i];
return sum >= 0;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 0;i < n;i++) cin >> s[i];
for (int i = 0;i < n;i++) cin >> c[i];
double l = 0, r = 1e3;
while (r - l >= 1e-6) {
double mid = (l + r) / 2;
if (check(mid)) l = mid;
else r = mid;
}
cout << fixed << setprecision(6) << l << '\n';
return 0;
}

NC17400 gpa的更多相关文章

  1. 16090202(剑灵GPA)

    [目标] 剑灵GPA [思路] 1 2 绘制角色DrawCall body 5526面片 2.1[第一个DrawCall]63 RT 这个DrawCall PS VS 参数列表 VS // // Ge ...

  2. 使用 Intel GPA 与 分析3D程序和抓取模型

    原文链接在这里 http://dev.cra0kalo.com/?p=213 背景信息 Intel的GPA本身是一款图形分析软件,并没有设计从3D程序里抓取模型资源的功能,但这里作者是通过hook G ...

  3. Improving the GPA 分类: 贪心 HDU 比赛 2015-08-08 16:12 11人阅读 评论(0) 收藏

    Improving the GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...

  4. The calculation of GPA

    Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...

  5. HDU 4968 Improving the GPA

    Improving the GPA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  6. HDOJ 1202 The calculation of GPA

    Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...

  7. 使用GPA针对android应用的绘制分析

    使用GPA针对android应用的绘制分析 以前经常用GPA来perf端游的绘制,很多perf工具例如perfhud,pix对于加壳的程序总是束手无策,但是GPA却不受这个限制,可以自动HOOK 3D ...

  8. GPA简介

    GPA(Graphics Performance Analyzers)是Intel公司提供的一款免费的跨平台性能分析工具. 填写e-mail.name和country并提交后,就会收到一封有专属下载链 ...

  9. hdu 4968 最大最小gpa

    http://acm.hdu.edu.cn/showproblem.php?pid=4968 给定平均分和科目数量,要求保证及格的前提下,求平均绩点的最大值和最小值. dp[i][j]表示i个科目,总 ...

随机推荐

  1. linux创建磁盘阵例10

    Linux创建RAID10 生产环境中用到的服务器一般都配备RAID阵列卡,尽管服务器的价格越来越便宜,但是我们没有必要为了做一个实验而去单独购买一台服务器,而是可以学会使用mdadm命令在Linux ...

  2. 半导体行业如何保持高效远程办公?因果集群(Causal Clustering)了解一下!

    什么是因果集群?因果集群是下一代多站点复制技术.它支持数据中心的分布式系统集群模型.借助于因果集群技术,可以让远程工作团队成员体验到更卓越的性能和更健壮的复制功能,确保您的团队始终以高效状态工作. 因 ...

  3. 【问题解决】'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.

    问题复述 今天项目组有人找我说之前部署的程序在测试环境没问题,到生产环境出现了奇怪的问题,点按钮没反应. 我通过腾讯会议发现他们的浏览器控制台上打出了如下错误: Access to XMLHttpRe ...

  4. Microsoft Graph 的 .NET 6 之旅

    这是一篇发布在dotnet 团队博客上由微软Graph首席软件工程师 Joao Paiva写的文章,原文地址: https://devblogs.microsoft.com/dotnet/micros ...

  5. CentOS配置epel源

    https://opsx.alibaba.com/mirror epel 配置方法 1.备份(如有配置其他epel源) mv /etc/yum.repos.d/epel.repo /etc/yum.r ...

  6. 无法启动报,To install it, you can run: npm install --save @/components/xxxx.vue

    运行的过程中后台报错 npm install --save @/components/xxx.vue 重装了node_modules依然没有用. 其实是组件路径写错了 总结 以后出现提醒安装那个vue ...

  7. Pandas 分组聚合 :分组、分组对象操作

    1.概述 1.1 group语法 df.groupby(self, by=None, axis=0, level=None, as_index: bool=True, sort: bool=True, ...

  8. pandas:数据迭代、函数应用

    1.数据迭代 1.1 迭代行 (1)df.iterrows() for index, row in df[0:5].iterrows(): #需要两个变量承接数据 print(row) print(& ...

  9. 「POI2012」井 Well

    description 你要挖井,\(n\)个地面的高度可视为\(h_i\),每次操作你可以将一个\(h_i-1\),你最多可执行\(m\)次操作. 你要任选其中一个\(h_i\)挖到\(0\),问你 ...

  10. goose消元

    ps.改了标题 魔板 思路:按序消除变量,用当前行(i)[行i消\(x_i\)元素],消后面的每一行的i元素 最后按逆序回代值 注意若有i~n行i元素系数都为0说明没有唯一解(其余x的解跟i元素有关) ...