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).

题意:有几门成绩,现在要求选N-K门,使得平均成绩最高,求最高平均成绩。

思路:01分数规划。

有三种需要掌握的01分数规划,之前最大流的时候遇到过,现在有些想法,有空再来实现。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const double eps=1e-;
int N,K;
struct in
{
double x,y;
double res;
bool friend operator <(in a,in b){
return a.res>b.res;
}
}a[];
bool check(double Mid)
{
for(int i=;i<=N;i++) a[i].res=a[i].x-Mid*a[i].y;
sort(a+,a+N+);
double tx=;
for(int i=;i<=K;i++) tx+=a[i].res;
if(tx>=-eps) return true;
return false;
}
int main()
{
while(~scanf("%d%d",&N,&K)&&(N||K)){
K=N-K;
for(int i=;i<=N;i++) scanf("%lf",&a[i].x),a[i].x*=100.0;
for(int i=;i<=N;i++) scanf("%lf",&a[i].y);
double L=,R=,Mid,ans=;
while(R-L>eps){
Mid=(L+R)/;
if(check(Mid)) ans=Mid,L=Mid+eps;
else R=Mid-eps;
}
printf("%.0lf\n",ans);
}
return ;
}

POJ2976:Dropping tests(01分数规划入门)的更多相关文章

  1. [poj2976]Dropping tests(01分数规划,转化为二分解决或Dinkelbach算法)

    题意:有n场考试,给出每场答对的题数a和这场一共有几道题b,求去掉k场考试后,公式.的最大值 解题关键:01分数规划,double类型二分的写法(poj崩溃,未提交) 或者r-l<=1e-3(右 ...

  2. POJ2976 Dropping tests —— 01分数规划 二分法

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

  3. POJ2976 Dropping tests(01分数规划)

    题意 给你n次测试的得分情况b[i]代表第i次测试的总分,a[i]代表实际得分. 你可以取消k次测试,得剩下的测试中的分数为 问分数的最大值为多少. 题解 裸的01规划. 然后ans没有清0坑我半天. ...

  4. POJ2976 Dropping tests 01分数规划

    裸题 看分析请戳这里:http://blog.csdn.net/hhaile/article/details/8883652 #include<stdio.h> #include<a ...

  5. Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8176   Accepted: 2862 De ...

  6. POJ 2976 Dropping tests 01分数规划 模板

    Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 ...

  7. POJ 2976 Dropping tests 01分数规划

    给出n(n<=1000)个考试的成绩ai和满分bi,要求去掉k个考试成绩,使得剩下的∑ai/∑bi*100最大并输出. 典型的01分数规划 要使∑ai/∑bi最大,不妨设ans=∑ai/∑bi, ...

  8. $POJ$2976 $Dropping\ tests$ 01分数规划+贪心

    正解:01分数规划 解题报告: 传送门! 板子题鸭,,, 显然考虑变成$a[i]-mid\cdot b[i]$,显然无脑贪心下得选出最大的$k$个然后判断是否大于0就好(,,,这么弱智真的算贪心嘛$T ...

  9. POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))

    题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...

  10. 【POJ2976】Dropping tests - 01分数规划

    Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...

随机推荐

  1. 词法分析器 /c++实现

    #include<iostream> #include<string> #include<vector> #include<map> #include& ...

  2. hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

    题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...

  3. 激活win10系统的方法(亲测)

    WIN+X 按A (或者点击左下角有个windows小图标“鼠标右键”选择选择“命令提示符号(管理员)”) 输入下面命令,回车(一行按一个回车键)slmgr.vbs /upkslmgr /ipk W2 ...

  4. JFinal2.0极速开发视频教程发布【转】

    原文:http://blog.dreamlu.net/blog/79 目前JFinal越来越火爆,而且使用的公司越来越多.鉴于市面上JFinal的学习资源不多,我们开始基于JFinal2.0录制学习视 ...

  5. T2639 约会计划 codevs

    http://codevs.cn/problem/2639/ 题目描述 Description cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而 ...

  6. 注解@RequestMapping value 用法

    本文引自:https://blog.csdn.net/qq_33811662/article/details/80864784 RequestMapping是一个用来处理请求地址映射的注解,可用于类. ...

  7. ZJGSU-ACM OJ 心得

    一个我觉得蛮重要的问题,也是会经常碰到的问题 就是觉得自己对的代码提交到OJ发现输出超限 我是真的输出超限了吗? QAQ 其实,不然. 我把这类问题分为几类: (一):死循环:while(1) 比如以 ...

  8. [转】 nginx rewrite规则

    http://www.cnblogs.com/cgli/archive/2011/05/16/2047920.html 最近在VPS上尝试配置安装一个网站,VPS安装了LNMP(Linux+Nginx ...

  9. 【Android小项目】找不同,改编自&quot;寻找房祖名&quot;的一款开源小应用。

    近期在微信朋友圈"寻找房祖名"和"万里寻刀"这类小游戏比較火.我试着写了一个android版本号的,里面全是一系列的形近字,实现原理非常easy:用一个Grid ...

  10. Java之基于Eclipse搭建SSH框架(下)

    在上篇博客里,我简介了Tomcat滴配置与Struts2滴搭建,假设对这个还不会滴童鞋去看一下我滴上篇博客<Java之基于Eclipse搭建SSH框架(上)>.今天我们接着上篇博客滴内容. ...