NC17400 gpa
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\) 个课程。答案的可行性函数符合单调性,且答案是唯一零点,于是二分答案,有如下公式:
\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的更多相关文章
- 16090202(剑灵GPA)
[目标] 剑灵GPA [思路] 1 2 绘制角色DrawCall body 5526面片 2.1[第一个DrawCall]63 RT 这个DrawCall PS VS 参数列表 VS // // Ge ...
- 使用 Intel GPA 与 分析3D程序和抓取模型
原文链接在这里 http://dev.cra0kalo.com/?p=213 背景信息 Intel的GPA本身是一款图形分析软件,并没有设计从3D程序里抓取模型资源的功能,但这里作者是通过hook G ...
- 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) ...
- The calculation of GPA
Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...
- HDU 4968 Improving the GPA
Improving the GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDOJ 1202 The calculation of GPA
Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...
- 使用GPA针对android应用的绘制分析
使用GPA针对android应用的绘制分析 以前经常用GPA来perf端游的绘制,很多perf工具例如perfhud,pix对于加壳的程序总是束手无策,但是GPA却不受这个限制,可以自动HOOK 3D ...
- GPA简介
GPA(Graphics Performance Analyzers)是Intel公司提供的一款免费的跨平台性能分析工具. 填写e-mail.name和country并提交后,就会收到一封有专属下载链 ...
- hdu 4968 最大最小gpa
http://acm.hdu.edu.cn/showproblem.php?pid=4968 给定平均分和科目数量,要求保证及格的前提下,求平均绩点的最大值和最小值. dp[i][j]表示i个科目,总 ...
随机推荐
- Go 语言字符串常见操作
@ 目录 1. 字节数组 2. 头尾处理 3. 位置索引 4. 替换 5. 统计次数 6. 重复 7. 大小写 8. 去除字符 9. 字符串切片处理 10. 数值处理 1. 字节数组 字节与字符的区别 ...
- XCTF练习题---MISC---就在其中
XCTF练习题---MISC---就在其中 flag:flag{haPPy_Use_0penSsI} 解题步骤: 1.观察题目,下载附件 2.拿到手以后发现是一个数据包格式,直接上Wireshark查 ...
- 网络协议之:Domain name service DNS详解
目录 简介 DNS的功能 DNS的组成 域名空间Domain name space Name servers DNS的工作流程 DNS资源记录 DNS消息的结构 总结 简介 现在是互联网的世界,大家从 ...
- 虚拟机(Vmvare)与配置,得到一台学习机
准备: 1.Vmvare 2.CentOS7.4镜像 安装与配置操作系统: 1.配置虚拟机上网 2.配置静态ip地址 开始安装 1. 2.直接下一步选择我们准备好的镜像,然后下一步 3.修改虚拟机的名 ...
- 等了整整12年!Linux QQ昨天终于更新了!
一个执着于技术的公众号 前言 2020年4月1日,腾讯QQ Linux版迎来最新版发布,详细版本号为v2.0.0 Beta2.上一个版本v2.3.2发布于2019年10月24日,时隔160天又迎来了更 ...
- go thrift 开发
thrift 从 0.9.1版本开始,可以完美支持 go 语言,可以完美的实现跨语言的 rpc 调用了.下面以 go 和 java 语言相互调用为例. 编辑协议文件,go 语言示例 /** examp ...
- MinIO学习
1.Minio及背景 Minio是一个开源的分布式文件存储系统,它基于 Golang 编写,虽然轻量,却拥有着不错的高性能,可以将图片.视频.音乐.pdf这些文件存储到多个主机,可以存储到多个Linu ...
- redis & redis sentinel
Redis 命令参考 Redis Sentinel Cheat Sheet Redis 哨兵节点之间相互自动发现机制(自动重写哨兵节点的配置文件) Redis哨兵模式(sentinel)学习总结及部署 ...
- c++ web框架实现之静态反射实现
0 前言 最近在写web框架,框架写好后,需要根据网络发来的请求,选择用户定义的servlet来处理请求.一个问题就是,我们框架写好后,是不知道用户定义了哪些处理请求的类的,怎么办? 在java里有一 ...
- linux篇-Centos7jdk安装
2.1查看现有JDK #rpm -qa|grep jdk (如果有其他版本的JDK建议卸载) 卸载其他版本的JDK命令 #yum –y remove java-1.6.0 #yum –y remov ...