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. 一种O(n)时间复杂度的计数排序算法和Top N热词算法

    排序算法是研究非常广泛且超级经典的算法,主流排序算法的时间复杂度基本都在O(nlogn). 今天就介绍一种以hash表为基础的,时间复杂度能够达到O(n)的排序算法--计数排序: 同时基于它的思想,完 ...

  2. echarts基本使用与注意事项

    npm 安装echarts npm install echarts -D 使用流程 1. 引入echarts,并配置成全局方法 vue2 import * as echarts from 'echar ...

  3. Bugku CTF练习题---加密---聪明的小羊

    Bugku CTF练习题---加密---聪明的小羊 flag:KEY{sad23jjdsa2} 解题步骤: 1.观察题目,发现其中的信息 2.经过题目判断,得知该题属于栅栏密码的一种,并且介绍中表明了 ...

  4. Nessus简单介绍与安装

    1.Nessus简单介绍与安装 1.Nessus简介 Nessus号称是世界上最流行的漏洞扫描程序,全世界有超过75000个组织在使用它.该工具提供完整的电脑漏洞扫描服务,并随时更新其漏洞数据库.Ne ...

  5. 团队Beta3

    队名:观光队 链接 组长博客 作业博客 组员实践情况 王耀鑫 **过去两天完成了哪些任务 ** 文字/口头描述 学习 展示GitHub当日代码/文档签入记录 接下来的计划 完成短租车,页面美化 **还 ...

  6. Linux网络重点知识总结性梳理

    一个执着于技术的公众号 1 OSI七层模型 层次 说明 功能/协议 应用层 应用程序及接口 提供应用程序的接口:FTP telnet http pop3等 表示层 对数据进行转换.加密和压缩 将上层的 ...

  7. linux下nginx软件的学习

    参考博客 1.nginx是什么 nginx是一个开源的,支持高性能,高并发的web服务和代理服务软件.它是开源的软件. nginx比它大哥apache性能改进许多,nginx占用的系统资源更少,支持更 ...

  8. java高级用法之:绑定CPU的线程Thread-Affinity

    目录 简介 Java Thread Affinity简介 AffinityLock的使用 使用API直接分配CPU 总结 简介 在现代计算机系统中,可以有多个CPU,每个CPU又可以有多核.为了充分利 ...

  9. 跨云平台与物理专线使用Vxlan实现两地二层互通,并使用ospf与bgp做底层链路主备

    Vxlan基础,已掌握可略过 VXLAN网络架构 VXLAN是NVO3中的一种网络虚拟化技术,通过将原主机发出的数据包封装在UDP中,并使用物理网络的IP.MAC作为外层头进行封装,然后在IP网络上传 ...

  10. mysql allow remote host

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEG ...