Dropping tests
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12187   Accepted: 4257

Description

In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be

.

Given your test scores and a positive integer k, determine how high you can make your cumulative average if you are allowed to drop any k of your test scores.

Suppose you take 3 tests with scores of 5/5, 0/1, and 2/6. Without dropping any tests, your cumulative average is . However, if you drop the third test, your cumulative average becomes .

Input

The input test file will contain multiple test cases, each containing exactly three lines. The first line contains two integers, 1 ≤ n ≤ 1000 and 0 ≤ k < n. The second line contains n integers indicating ai for
all i. The third line contains n positive integers indicating bi for all i. It is guaranteed that 0 ≤ ai ≤ bi ≤ 1, 000, 000, 000. The end-of-file is marked by a test case
with n = k = 0 and should not be processed.

Output

For each test case, write a single line with the highest cumulative average possible after dropping k of the given test scores. The average should be rounded to the nearest integer.

Sample Input

3 1
5 0 2
5 1 6
4 2
1 2 7 9
5 6 7 9
0 0

Sample Output

83
100

Hint

To avoid ambiguities due to rounding errors, the judge tests have been constructed so that all answers are at least 0.001 away from a decision boundary (i.e., you can assume that the average is never 83.4997).

Source

————————————————————————————————

给出n和分数,可以去其中m个,求剩下的分子之和除以分母之和最大

思路:二分答案,验证去了m个后能否达到

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int n,m;
struct node{
LL a,b;
}p[100005];
double k; bool cmp(node a,node b)
{
double x=a.a-(a.b*k);
double y=b.a-(b.b*k);
return x>y;
} bool ok(double mid)
{
k=mid;
sort(p,p+n,cmp);
LL x=0,y=0;
for(int i=0;i<n-m;i++)
{
x+=p[i].a;
y+=p[i].b;
}
double ans=x*1.0/y;
if(ans>=mid)
return 1;
return 0; } int main()
{
while(~scanf("%d%d",&n,&m)&&(m||n))
{
for(int i=0;i<n;i++)
scanf("%lld",&p[i].a);
for(int i=0;i<n;i++)
scanf("%lld",&p[i].b); double l=0,r=1;
while(r-l>1e-5)
{
double mid=(l+r)/2;
if(ok(mid))
{
l=mid;
}
else
r=mid;
}
l*=100;
printf("%.0f\n",l);
}
return 0;
}

HDU2976 Dropping tests 2017-05-11 18:10 39人阅读 评论(0) 收藏的更多相关文章

  1. const char*, char const* and char *const 分类: C/C++ OpenCV 2014-11-08 18:10 114人阅读 评论(0) 收藏

    const char*, char const*, char*const的区别问题几乎是C++面试中每次都会有的题目.  事实上这个概念谁都有只是三种声明方式非常相似很容易记混.  Bjarne在他的 ...

  2. Codeforces777E. Hanoi Factory 2017-05-04 18:10 42人阅读 评论(0) 收藏

    E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. spark1.3.1使用基础教程 分类: B8_SPARK 2015-04-28 11:10 1651人阅读 评论(0) 收藏

      spark可以通过交互式命令行及编程两种方式来进行调用: 前者支持scala与python 后者支持scala.python与java 本文参考https://spark.apache.org/d ...

  4. 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏

    制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...

  5. Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏

    全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...

  6. HDU6024 Building Shops 2017-05-07 18:33 30人阅读 评论(0) 收藏

    Building Shops                                                             Time Limit: 2000/1000 MS ...

  7. HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏

    Automatic Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  8. HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏

    Coprime Sequence                                                        Time Limit: 2000/1000 MS (Ja ...

  9. codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. cat 生成文件 运行脚本

    nohup python -u day_std_cid_list_data_done.py >eee1.log 2>&1 & 后台运行python脚本 hadoop fs ...

  2. Python在pycharm中编程时应该注意的问题汇总

    1.缩进问题 在 pycharm 中点击 enter 自动进行了换行缩进,此时应该注意:比如 if   else  语句,后面跟着打印输出 print 的时候,一定注意是要if语句下的输出还是else ...

  3. php 利用迭代器遍历文件夹

    1.遍历文件夹 scandir 2.原生的迭代器Iterrate $scan_dir = "txtDir"; //下面会遍历txtDir 下面所有字文件夹中的文件哦 $dir_it ...

  4. C# split分割多个字符

    string[] myAgent = agentInfo.Split(new string[] { "$#$" }, StringSplitOptions.None);

  5. wordpress 下载主题模板、更新报错 No working transports found解决办法

    出错原因是PHP没有开启curl. windows下开启方法如下 1. 将php.ini中的;extension=php_curl.dll前的分号去掉, 2. 将php中libeay32.ll, ss ...

  6. 指针c艹

    #include <iostream> using namespace std;int value=1;void func(int *p){ p=&value; }void fun ...

  7. 【Linux 进程】之关于父子进程之间的数据共享分析

    之前我们通过fork()函数,得知了父子进程之间的存在着代码的拷贝,且父子进程都相互独立执行,那么父子进程是否共享同一段数据,即是否存在着数据共享.接下来我们就来分析分析父子进程是否存在着数据共享. ...

  8. 从RTTI谈C++的向下转型

    转自:http://blog.chinaunix.net/uid-28541347-id-4251713.html 从RTTI谈C++的向下转型 1.什么是RTTI? RTTI 是“Runtime T ...

  9. 关于mybatis缓存配置详解

    一级缓存: 一级缓存是默认的. 测试:在WEB页面同一个查询执行两次从日志里面看同样的sql查询执行两次. 2次sql查询,看似我们使用了同一个sqlSession,但是实际上因为我们的dao继承了S ...

  10. Excel单元格内容批量加前缀

    比如83190001在A1单元格,要在A列单元内容前面批量加0,在B1输入公式="0"&A1然后向下复制再把B列复制的结果再复制一下:然后到新的一列粘贴,在“粘贴选项”中选 ...