Dropping tests
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12515   Accepted: 4387

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门课,每门课有一个总分值b和我的得分a,我的总成绩是 ,在能去掉k门课的情况下,求我能得到的最大成绩。

代码:

//和上一题一样。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
const double esp=0.000001;
int n,k;
double x;
struct Lu{
double a,b;
bool operator < (const Lu &p)const{
return a-x*b>p.a-x*p.b;
}
}L[maxn];
bool solve(double m){
x=m;
sort(L,L+n);
double tmp1=,tmp2=;
for(int i=;i<n-k;i++){
tmp1+=L[i].a;
tmp2+=L[i].b;
}
return tmp1-m*tmp2>=;
}
int main()
{
while(scanf("%d%d",&n,&k)==&&(n+k)){
for(int i=;i<n;i++) scanf("%lf",&L[i].a);
for(int i=;i<n;i++) scanf("%lf",&L[i].b);
double l=,r=,ans;
while(r-l>esp){
double m=(l+r)/2.0;
if(solve(m)){
l=m;
}else r=m;
}
printf("%.0lf\n",l*);
}
return ;
}

POJ 2976 二分的更多相关文章

  1. 二分算法的应用——最大化平均值 POJ 2976 Dropping tests

    最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...

  2. 【poj 2976】Dropping tests(算法效率--01分数规划 模版题+二分){附【转】01分数规划问题}

    P.S.又是一个抽时间学了2个小时的新东西......讲解在上半部分,题解在下半部分. 先说一下转的原文:http://www.cnblogs.com/perseawe/archive/2012/05 ...

  3. POJ 2976 3111(二分-最大化平均值)

    POJ 2976 题意 给n组数据ai,bi,定义累计平均值为: 现给出一个整数k,要求从这n个数中去掉k个数后,最大累计平均值能有多大?(四舍五入到整数) 思路 取n−k个数,使得累计平均值最大. ...

  4. poj 2976(二分搜索+最大化平均值)

    传送门:Problem 2976 参考资料: [1]:http://www.hankcs.com/program/cpp/poj-2976-dropping-tests-problem-solutio ...

  5. POJ - 2976 Dropping tests && 0/1 分数规划

    POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...

  6. POJ - 2018 二分+单调子段和

    依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...

  7. POJ 2976 Dropping tests(01分数规划入门)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11367   Accepted: 3962 D ...

  8. POJ 2976 Dropping tests 【01分数规划+二分】

    题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  9. POJ 2976 Dropping tests:01分数规划【二分】

    题目链接:http://poj.org/problem?id=2976 题意: 共有n场考试,每场考试你得的分数为a[i],总分为b[i]. 你可以任意去掉k场考试. 问你最大的 100.0 * ( ...

随机推荐

  1. VBS简明教程

    VBS简明教程   一.输出 VBS的输出使用函数Msgbox调用对话框进行输出. Msgbox(message) Message为要输出的信息 二.输入 VBS的输入,调用函数Inputbox()进 ...

  2. df -h 卡住

    mount 检查是否有挂载nfs的分区       网络挂载     如果有请umount  -l   /相应目录      umount -l  10.74.82.205:/letv/fet/nfs ...

  3. 第一届"进化论杯"月赛 解题报告

    Problem A: derivative 思路:水题.算出二阶导数,直接 printf 结果. 在求出二阶导数后可以不立刻化简,此时式中带有大量 e^(-x) 项.此时直接可以代入 ln|x0|,把 ...

  4. 寒假学习计划——MOOC

    课程 西安交通大学[https://www.icourse163.org/course/XJTU-46006?tid=1002265006] 理由 本身中国大学mooc里c++课程不多,完结了能够有很 ...

  5. 从电梯问题,看c和c++之间的区别(有点懂了)错觉错觉

    磕磕碰碰的也相继用c和c++构造了不少的电梯了.虽然对自我的表现不满意,但是总体来说还是有一定的收获的,对于c和c++之间的区别感觉也摸到了一点点门道了... 用c语言构造电梯的步骤: 第一步: 分析 ...

  6. 在LaTex中插入电路图的方法(插入图片)

    主要的需求是要在文档中插入电路图. 有两种方法,一种是直接在LaTex中绘制电路图,使用的库主要是circ和circuitikz 另一种是在其他软件上绘制电路图,转成特定图像格式后,在Latex中插入 ...

  7. lintcode-181-将整数A转换为B

    181-将整数A转换为B 如果要将整数A转换为B,需要改变多少个bit位? 注意事项 Both n and m are 32-bit integers. 样例 如把31转换为14,需要改变2个bit位 ...

  8. Java模块化开发

    包配置, 静态资源, 视图解析器, 数据库,

  9. [OS] 生产者-消费者问题(有限缓冲问题)

    ·最简单的情形--(一个生产者 + 一个消费者 + 一个大小为1的有限缓冲) 首先来分析其中的同步关系: ·必须在生产者放入一个产品之后,消费者才能够从缓冲中取出产品来消费.·只有在消费者从缓冲区中取 ...

  10. JS作用域-面向对象

    1. 其它语言是以代码块作为作用域的.下面程序会报错(如C,C++中),因为局部变量name只在{   }代码块中生效.打印console.writeline(name)中的name时就会报错. pu ...