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 aifor 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个考试,每个考试有ai和bi两个值,最后成绩由上面的公式求得。幸运的是,可以放弃K个科目,求最大化最后的成绩。

思路:这是一道简单的最大化平均值模板题,化简出(ai-mid*bi)>0,求n-k前项。

AC代码:

#include<stdio.h>
#define INF 0x3f3f3f3f
#include<algorithm>
using namespace std;
bool cmp(double x,double y)
{
return x>y;
}
int n,k;
double y[];
int a[];
int b[];
bool C(double mid)
{
for(int i= ; i<n ; i++)
{
y[i]=a[i]-mid*b[i];
}
sort(y,y+n,cmp);
double sum=;
for(int i= ; i<n-k ; i++)
{
sum+=y[i];
}
if(sum>=)
return true;
return false;
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
if(n==&&k==)
break;
for(int i= ; i<n ; i++)
scanf("%d",&a[i]);
for(int i= ; i<n ; i++)
scanf("%d",&b[i]);
double st=,en=INF;
for(int i= ; i<= ; i++)
{
double mid=(st+en)/;
if(C(mid))
st=mid;
else
en=mid;
} printf("%.0f\n",st*);
}
}

POJ:2976 Dropping tests(二分+最大化平均值)的更多相关文章

  1. POJ 2976 Dropping tests (最大化平均值)

    题目链接:click here~~ [题目大意]给你n个分数的值,要求最小不选k个,使得最后分数相加结果平均值最大 [解题思路]:最大化平均值:參见:click here~~ 代码: #include ...

  2. POJ 2976 Dropping tests(最大化平均值 or 01整数规划)

    题目链接 忽略运算符逻辑导致奇怪的错误(代码中指明位置了) 输出没加0.5,WA. 还有,注意特殊情况k=0,所以scanf("%d%d", &n, &k)& ...

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

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

  4. POJ 2976 Dropping tests [二分]

    1.题意:同poj3111,给出一组N个有价值a,重量b的物品,问去除K个之后,剩下的物品的平均值最大能取到多少? 2.分析:二分平均值,注意是去除K个,也就是选取N-K个 3.代码: # inclu ...

  5. POJ 2976 Dropping tests (二分+贪心)

    题意:给定 n 个分数,然后让你去年 m 个分数,使得把剩下的所有的分子和分母都相加的分数最大. 析:这个题并不是分子越大最后结果就越大,也不是整个分数越大,最后结果就越大的,我们可以反过来理解,要去 ...

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

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

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

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

  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分数规划---二分(最大化平均值))

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

随机推荐

  1. siciyuan开源项目观光指南

    观光方式: 1.从UI到后台,先针对每个界面UI观察结构 2.再观察如何初始化和注入数据 3.针对2所用的后台方法进行概览 4.对3中方法进行深入研究 5.选择一个模块进行重写 6.重复5,搭建大体框 ...

  2. JS中的!= 、== 、!==、===的用法和区别

    与c++中每一种类型都有明确的的定义不同:因JS中var定义存在,未具体区分类型,!=与==不能包含所有的条件,故加入!==与===用法: var num = 1; var str = '1'; va ...

  3. IFC4 在线参考手册

    国内地址1:http://www.vfkjsd.cn/ifc/ifc4/index.htm 国内地址2:http://www.bim-times.com/ifc/ifc4/index.htm 官方地址 ...

  4. C语言-郝斌笔记-004判断是否为回文数

    判断是否为回文数 # include <stdio.h> int main(void) { int val; //存放待判断的数字 int m; ; printf("请输入您需要 ...

  5. 华为2013年西安java机试题目:如何过滤掉数组中的非法字符。

    这道题目为记忆版本: 题目2描述: 编写一个算法,过滤掉数组中的非法字符,最终只剩下正式字符. 示例:输入数组:“!¥@&HuaWei*&%123” 调用函数后的输出结果,数组:“Hu ...

  6. docker卸载与安装

    sudo apt remove docker.io 报错如下: Reading package lists... Done Building dependency tree Reading state ...

  7. WordCount编码与测试

    1. github项目地址:https://github.com/wwwwu/WordCount 2.PSP表格: PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning ...

  8. 关于 windows mobile 进程操作的方法

    #region Process class /// <summary> /// Summary description for Process. /// </summary> ...

  9. Python--socket和threading编程

    网络编程基础(一) TCP/IP协议 OSI/RM协议 特点:独立于计算机硬件和操作系统,统一分配网络地址,提供可靠服务,隔离了物理网络的硬件差异 协议分层(百度):网络接口层:IEE802.3(以太 ...

  10. 多线程学习-基础( 十)一个synchronized(){/*代码块*/}简单案例分析

    一.提出疑惑 上一篇文章中,分析了synchronized关键字的用法.但是好像遗漏了一种情况. 那就是: synchronized(obj){/*同步块代码*/} 一般有以下几种情况: (1)syn ...