gpa

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

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述

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

 
 
 
 
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<math.h>
  5. #include<algorithm>
  6. #define MAX 100005
  7. #define INF 0x3f3f3f3f
  8. #define MOD 1000000007
  9. using namespace std;
  10. typedef long long ll;
  11.  
  12. double s[MAX],c[MAX],cnt[MAX];
  13.  
  14. int main()
  15. {
  16. int n,k,i;
  17. scanf("%d%d",&n,&k);
  18. for(i=;i<=n;i++){
  19. scanf("%lf",&s[i]);
  20. }
  21. for(i=;i<=n;i++){
  22. scanf("%lf",&c[i]);
  23. }
  24. double l=,r=;
  25. while(r-l>0.000001){
  26. double mid=(l+r)/;
  27. for(i=;i<=n;i++){
  28. cnt[i]=s[i]*c[i]-mid*s[i];
  29. }
  30. sort(cnt+,cnt+n+);
  31. double fx=;
  32. for(i=k+;i<=n;i++){
  33. fx+=cnt[i];
  34. }
  35. if(fx>=) l=mid;
  36. else r=mid;
  37. }
  38. printf("%f\n",l);
  39. return ;
  40. }

牛客多校5 A-gpa(01分数规划)的更多相关文章

  1. P2877 [USACO07JAN]牛校Cow School(01分数规划+决策单调性分治)

    P2877 [USACO07JAN]牛校Cow School 01分数规划是啥(转) 决策单调性分治,可以解决(不限于)一些你知道要用斜率优化却不会写的问题 怎么证明?可以暴力打表 我们用$ask(l ...

  2. POJ 2728 Desert King (01分数规划)

    Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions:29775   Accepted: 8192 Descr ...

  3. 2019牛客多校第二场 A Eddy Walker(概率推公式)

    2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...

  4. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  5. 牛客多校第一场 B Inergratiion

    牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...

  6. 牛客多校第三场 F Planting Trees

    牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...

  7. 牛客多校第三场 G Removing Stones(分治+线段树)

    牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...

  8. 牛客多校第四场sequence C (线段树+单调栈)

    牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...

  9. 牛客多校第3场 J 思维+树状数组+二分

    牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...

随机推荐

  1. JSON格式之GSON解析

    JSON格式之GSON解析 最近在做websocket相关,项目需要JSON解析.相较之下感觉google的GSON解析不错. JAVA后台 Gson提供了fromJson()方法来实现从Json相关 ...

  2. vs2013工程技巧

    1 vs工程输出了dll和lib,分别是什么,有什么用? 当设置工程property的Project Defaults的Configuration Type为dll时,不光会生成该动态链接库的dll文 ...

  3. Wix Burn运行64位dism.exe的问题

    主要的问题是Burn是一个32位程序,在64位机器上它启动的进程都会被重定向到wow64目录下,也就是说它运行的dism.exe最终会是32位的.解决的方法就是用wix提供的QtExec64CmdLi ...

  4. Django一对多的创建

    1.一对多的应用场景: 例如:创建用户信息时候,需要选择一个用户类型[普通用户][金牌用户][铂金用户]等. 2.方法: class Business(models.Model): buss=mode ...

  5. python仪表盘

    1.在这里可以看到pyecharts中有定义好的各种图标类. 复制上面代码,会出现“ModuleNotFoundError: No module named 'pyecharts'”. pip ins ...

  6. 微信小程序开发:学习笔记[7]——理解小程序的宿主环境

    微信小程序开发:学习笔记[7]——理解小程序的宿主环境 渲染层与逻辑层 小程序的运行环境分成渲染层和逻辑层. 程序构造器

  7. Android RelativeLayout相对布局

    RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列. 相对布局常用属性: 子类控件相对子类控件:值是另外一个控件的id android:layout_above-- ...

  8. 大数据- 自定义Log4j日记

    1.新建一个java project,在src下新建一个lib文件夹和 rescources 文件夹,resources文件夹不能命名错误. 点击File——>project Structure ...

  9. CSS样式命名整理

    CSS样式命名整理 页面结构 容器: container/wrap 整体宽度:wrapper 页头:header 内容:content 页面主体:main 页尾:footer 导航:nav 侧栏:si ...

  10. JavaUtil_03_图片处理工具类

    一.源码 功能:缩放图像.切割图像.图像类型转换.彩色转黑白.文字水印.图片水印等 package com.ray.dingtalk.util; import java.awt.AlphaCompos ...