Dropping tests
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9329   Accepted: 3271

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
将条件写为(n&&k)。无限WA。
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAXN=;
const double EPS=1.0e-6;
int n,k;
int a[MAXN],b[MAXN];
bool test(double x)
{
double y[MAXN];
for(int i=;i<n;i++)
{
y[i]=a[i]-x*b[i];
}
sort(y,y+n);
double sum=;
for(int i=k;i<n;i++)
{
sum+=y[i];
}
return sum>=0.0;
}
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 l=;
double r=0x3f3f3f3f;
while(fabs(r-l)>EPS)
{
double mid=(l+r)/;
if(test(mid)) l=mid;
else r=mid;
}
int res=(int)(l*+0.5);
printf("%d\n",res);
}
return ;
}

POJ2976(最大化平均值)的更多相关文章

  1. POJ-2976 Dropping tests---二分最大化平均值

    题目链接: https://cn.vjudge.net/problem/POJ-2976 题目大意: 给定n个二元组(a,b),扔掉k个二元组,使得剩下的a元素之和与b元素之和的比率最大 解题思路: ...

  2. 【二分查找-最大化平均值】POJ2976 - Dropping Test

    [题目大意] 给出n组ai和bi,去掉k个使得a的总和除以b的总和最大. [思路] 也就是取(n-k)个数,最大化平均值,见<挑战程序设计竞赛>P144,最后公式为c(x)=((ai-x* ...

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

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

  4. POJ_3111_K_Best_(二分,最大化平均值)

    描述 http://poj.org/problem?id=3111 n个珠宝,第i个有价值v[i]和重量w[i],要从总选k个,使得这k个的(价值之和)/(重量之和)即平均价值最大,输出选中的珠宝编号 ...

  5. POJ 3111 K Best(最大化平均值)

    题目链接:click here~~ [题目大意]有n个物品的重量和价值各自是Wi和Vi.从中选出K个物品使得单位重量的价值最大,输出物品的编号 [解题思路]:最大化平均值的经典.參见click her ...

  6. poj 3111 K Best 最大化平均值 二分思想

    poj 3111 K Best 最大化平均值 二分思想 题目链接: http://poj.org/problem?id=3111 思路: 挑战程序竞赛书上讲的很好,下面的解释也基本来源于此书 设定条件 ...

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

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

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

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

  9. NYOJ 914 Yougth的最大化【二分/最大化平均值模板/01分数规划】

    914-Yougth的最大化 内存限制:64MB 时间限制:1000ms 特判: No 通过数:3 提交数:4 难度:4 题目描述: Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从 ...

随机推荐

  1. 【iOS和HTML 5交互】iOS中加载html5调用html方法和修改html5内容

    近期项目开发中用到了这方面的技术了,那我们一起来看看. 1.利用webView控件加载本地html5或者网络上html5 2.设置控制器为webView的代理,遵守协议 3.实现代理方法webView ...

  2. JAVA基础补漏--基础数据类型与引用数据类型

    ==在不同数据类型中意义不同. 在基础数据类型中,表示的是数值的比较. 在引用数据类型中,表示的是内存地址值的比较. 一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit), ...

  3. JavaScript实现的功能

    1.js事件阻止冒泡的应用 1)问题描述: 单机除了这两个元素,触发事件,: 可用阻止事件冒泡 2)解决方法: $('body').click(function(e){ $('#searchTree' ...

  4. Mybatis单个参数的if判断(针对异常:There is no getter for property..)------mybatis的内置对象

    这里有一个删除方法: int deleteByPrimaryKey(Integer id); 然后对应的sql的xml如下: <delete id="deleteByPrimaryKe ...

  5. centos 验证mysql的安装

    一.验证mysql是否安装 1.whereis mysql:如果安装了mysql就会显示mysql安装的地址 2.which mysql:查看文件的运行地址 3.chkconfig --list my ...

  6. 发布新版本遇见java.lang.ClassNotFoundException

    今天发布新版本到测试环境,服务器在启动时报了java.lang.ClassNotFoundException .刚开始我以为是代码中jar引的不对从而导致找不到相关类,后来在本地试了下发现项目可以正常 ...

  7. javascript是一种面向对象语言吗?如果是,您在javascript中是如何实现继承的呢

    ·oop(面向对象程序设计)中最常用到的概念有 1.对象,属性,方法 1>(对象:具体事物或抽象事物,名词) 2>(属性:对象的特征,特点,形容词) 3>(方法:对象的动作,动词) ...

  8. Java读取lob格式数据

    想要读出lob里面的图片数据,就要确认clob里面存储的是什么,一般情况下存储的base64的串串.所以就以base64为例,而Blob里面存储的大部分是图片数据,但也有xml内容数据. 1查询lob ...

  9. js 实现自动调出键盘

    在app中,在页面加载完成之后,给输入框添加一个focus,不能自动调出软键盘,可以用以下方式实现: //触发键盘 $("#content").on("touchstar ...

  10. css页面缩放

    如果原来的宽度是1200, 缩放之后宽度可能就变成了1560, 然后你本来的图片1200可能就开始显示不全了. 如果你的图片按100%显示的话,这个时候又正常了.