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. Hadoop YARN: 1/1 local-dirs are bad: /var/lib/hadoop-yarn/cache/yarn/nm-local-dir; 1/1 log-dirs are bad: /var/log/hadoop-yarn/containers hdfs硬盘90% yarn unhealthy

    1/1 local-dirs are bad: /var/lib/hadoop-yarn/cache/yarn/nm-local-dir; 1/1 log-dirs are bad: /var/log ...

  2. java之线程飞机大战制作

    import java.awt.Graphics; import java.util.ArrayList; import javax.swing.JFrame; import javax.swing. ...

  3. linux系统 使用git图形化管理工具———gitk

    运行安装命令: sudo apt-get install gitk 运行命令打开gitk : gitk

  4. 1、序列化 2、转义 3、eval 4、正则表达式 5、时间处理

    1.序列化 JSON.stringify(obj)   序列化 JSON.parse(str)        反序列化 2.转义 decodeURI( )                   URl中 ...

  5. SQL Server连接Oracle FAIL

    第一步 安装好oracle客户端Oracle 11.2.0.3 Client Win 64-bit,并配置好TNS信息 第二步,配置odbc信息 配置好odbc连接信息,sql server肯定不能直 ...

  6. windows 7 系统装机优化

    A:系统设置 1.控制面板\系统和安全\Windows Update\更改设置  把系统升级以及提示关闭      控制面板\系统和安全\Windows 防火墙\自定义设置 把专用网络和公共网络的防火 ...

  7. 利用JavaScriptCore实现简单的功能(阶乘)

    #import "RootViewController.h" #import <JavaScriptCore/JavaScriptCore.h> @interface ...

  8. p2444 病毒

    传送门 分析 先用AC自动机将所有字符串存起来,之后我们从根节点跑一遍dfs 判断时我们只需要判断这个环有没有任意一个字符串的结尾就可以判断是否安全了 注意一个节点的信息需要累加上它fail指针所指位 ...

  9. ZROI2018提高day3t1

    传送门 分析 我们可以用贪心的思想.对于所有并没有指明关系的数一定是将小的放在前面.于是我们按顺序在每一个已经指明大小顺序的数前面插入所有比它小且没有指明关系的数.详见代码. 代码 #include& ...

  10. 使用JMeter的Java Sampler轻松定制自己的benchmark

    做性能测试,接口测试,非常好 转自  http://www.iteye.com/topic/1123432 以前碰到更多的是WEB APP的性能测试,也许用得最多的是Loadrunner, Web S ...