链接:https://www.nowcoder.com/acm/contest/143/A
来源:牛客网

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 

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

输入描述:

  1. The first line has two positive integers n,k
  2.  
  3. The second line has n positive integers s[i]
  4.  
  5. The third line has n positive integers c[i]

输出描述:

  1. 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
  2. 1 2 3
  3. 3 2 1
输出例子:
  1. 2.33333333333

-->

示例1

输入

复制

  1. 3 1
  2. 1 2 3
  3. 3 2 1

输出

复制

  1. 2.33333333333

说明

  1. Delete the third course and the final score is 

备注:

  1. 1 n 10

5

  1.  
  2. 0 k < n
  3.  
  4. 1 s[i],c[i] 10

3

题意:给定 n 门课以及它们的学分和绩点,定义总绩点是所有课的加权平均数,给定一个数 k,  你可以删除最多 k 门课,求你的总绩点最大能到多少  1 <=n <=10^5

分析:假设最大总绩点为D,则题中式子可以转化成∑s[i](c[i]-D)=0

观察式子容易看出这是一个分数规划问题,我们可以通过二分D来解答,使左边式子结果最接近0的D即是最大总绩点D

以后类似的分数或者方程式不等式求解问题都可以用这种方式求解

01分数参考博客:https://blog.csdn.net/hhaile/article/details/8883652

AC代码:

  1. #include <map>
  2. #include <set>
  3. #include <stack>
  4. #include <cmath>
  5. #include <queue>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <string>
  9. #include <cstring>
  10. #include <iomanip>
  11. #include <iostream>
  12. #include <algorithm>
  13. #define ls (r<<1)
  14. #define rs (r<<1|1)
  15. #define debug(a) cout << #a << " " << a << endl
  16. using namespace std;
  17. typedef long long ll;
  18. const ll maxn = 1e5 + 10;
  19. const ll mod = 1e9 + 7;
  20. ll s[maxn], c[maxn], n, k;
  21. double le, ri, t[maxn];
  22. bool check( double x ) {
  23. for( ll i = 1; i <= n; i ++ ) {
  24. t[i] = s[i]*(c[i]-x);
  25. }
  26. sort( t+1, t+n+1 );
  27. double tmp = 0.0;
  28. for( ll i = k+1; i <= n; i ++ ) {
  29. tmp += t[i];
  30. }
  31. return tmp>0;
  32. }
  33. int main() {
  34. ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  35. cin >> n >> k;
  36. for( ll i = 1; i <= n; i ++ ) {
  37. cin >> s[i];
  38. }
  39. for( ll i = 1; i <= n; i ++ ) {
  40. cin >> c[i];
  41. ri = max( ri, (double)c[i] );
  42. }
  43. double mid;
  44. while( ri-le > 1e-6 ) {
  45. mid = (le+ri)/2;
  46. //debug(mid);
  47. if( check(mid) ) {
  48. le = mid;
  49. } else {
  50. ri = mid;
  51. }
  52. }
  53. printf("%.10lf\n",mid);
  54. return 0;
  55. }

  

牛客第五场多校 A gpa 分数规划(模板)的更多相关文章

  1. 牛客第五场多校 J plan 思维

    链接:https://www.nowcoder.com/acm/contest/143/J来源:牛客网 There are n students going to travel. And hotel ...

  2. 2019牛客第八场多校 E_Explorer 可撤销并查集(栈)+线段树

    目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)E_Explorer) 题意: 链接 题目类似:CF366D,Gym101652T 本题给你\(n(100000)\)个点\(m(1000 ...

  3. 牛客第三场多校 E Sort String

    链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequen ...

  4. 牛客第三场多校 H Diff-prime Pairs

    链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...

  5. 牛客第五场 G max 思维

    链接:https://www.nowcoder.com/acm/contest/143/G来源:牛客网 Give two positive integer c, n. You need to find ...

  6. PACM Team(牛客第三场多校赛+dp+卡内存+打印路径)

    题目链接(貌似未报名的不能进去):https://www.nowcoder.com/acm/contest/141/A 题目: 题意:背包题意,并打印路径. 思路:正常背包思路,不过五维的dp很容易爆 ...

  7. 2019牛客第八场多校 D_Distance 三维BIT或定期重建套路

    目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)D_Distance) 题意: 在三维空间\((n\times m\times h\le 100000)\)内,有\(q(q\le 100 ...

  8. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  9. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

随机推荐

  1. QTableView表格控件区域选择-自绘选择区域

    目录 一.开心一刻 二.概述 三.效果展示 四.实现思路 1.绘制区域 2.绘制边框 3.绘制 五.相关文章 原文链接:QTableView表格控件区域选择-自绘选择区域 一.开心一刻 陪完客户回到家 ...

  2. PID算法通俗理解,平衡车,倒立摆,适合不理解PID算法的人来看!

    先插句广告,本人QQ522414928,不熟悉PID算法的可以一起交流学习,随时在线(PID资料再我的另一篇博客里) 倒立摆资料连接↓ https://www.cnblogs.com/LiuXinyu ...

  3. QRCode生成二维码,jq QRCode生成二维码,QRCode生成电子名片

    [QRCode官网]http://phpqrcode.sourceforge.net/ PHP QRCode生成二维码 官网下载QRCode源码包,引入源码包中的 qrlib.php . <?p ...

  4. 一个项目的SpringCloud微服务改造过程

    SSO是公司一个已经存在了若干年的项目,后端采用SpringMVC.MyBatis,数据库使用MySQL,前端展示使用Freemark.今年,我们对该项目进行了一次革命性的改进,改造成SpringCl ...

  5. Python学习系列(三)Python 入门语法规则1

    一.注释 ''' 多行注释 ''' #单行注释 '''    #example1.1 测试程序  时间:4/17/2017 i1=input("请输入用户名:") i2=input ...

  6. 【游记】NOIP2018初赛

    声明 本文最初的版本创建之时,本人甚至只是个电脑的小白,因而不太会用电脑编辑文字,最初的版本写在一个Word文档里,被随意的丢弃在我杂乱无比的网盘的某一个角落,直到我决定整理自己的成长历程,将散落的游 ...

  7. LR(1)语法分析器生成器(生成Action表和Goto表)java实现(一)

    序言 : 在看过<自己实现编译器链接器>源码之后,最近在看<编译器设计>,但感觉伪代码还是有点太浮空.没有掌握的感觉,也因为内网几乎没有LR(1)语法分析器生成器的内容,于是我 ...

  8. centos虚拟机配置静态ip

    昨天在配置虚拟机的时候因为之前没有设置静态IP,而是使用DHCP动态分配的,导致关机后下次开机虚拟机的ip是随机变动的.严重影响了工作体验啊,遂设置静态ip以保全! 虚拟机使用的是CentOS6.5, ...

  9. 创建docker容器遇到的错误

    1.问题截图 2.问题描述 出现该问题就是docker版本和系统版本不兼容导致的. 现在的系统版本和docker的版本如下: 3.问题解决 安装低版本的docker或者高版本的系统(Centos7.4 ...

  10. linux安装MySQL后输入mysql显示 ERROR 2002 (HY000): Can't connect to local MySQL server through socket

    我是小白,大佬勿喷 *** linux安装MySQL后输入mysql显示 ERROR 2002 (HY000): Can't connect to local MySQL server through ...