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. 20165101刘天野 2017-2018-2 《Java程序设计》第3周学习总结

    20165101刘天野 2017-2018-2 <Java程序设计>第3周学习总结 编程语言的几个发展阶段 类 构造方法与对象的创建 类与程序的基本结构 参数传值 对象的组合 实例成员与类 ...

  2. 5.1深入理解计算机系统——系统级I/O

    一.UNIX I/O     在UNIX系统中有一个说法,一切皆文件.所有的I/O设备,如网络.磁盘都被模型化为文件,而所有的输入和输出都被当做对相应文件的读和写来执行.这种将设备映射为文件的方式,允 ...

  3. 写makefile时候的cc和gcc

    Linux 下 的 cc 和 gcc     Linux 下 的 cc 和 gcc 周银辉 在Linux下一会看到cc,另一会又看到gcc,感觉又点混乱的样子.它们是同一个东西么,有啥区别呢 一分为二 ...

  4. java.lang.NullPointerException报错的几种情况

    java.lang.NullPointerException报错的几种情况: 1.字符串变量未初始化: 2.接口类型的对象没有用具体的类初始化,比如: List stuList :这种情况就会报空指针 ...

  5. springmvc中url-url-pattern /和/*的区别

    在使用springmvc时,都会在web.xml中配置一个dispatchservlet,如下: <listener> <listener-class> org.springf ...

  6. 【P1947】笨笨当粉刷匠(DP+前缀和)

    这个题乍一看觉得挺简单的,事实上却完全不是.首先,这个题看上去无脑直接刷就可以然而因为刷的次数远远大于木板的个数所以不行,然后开始考虑DP,自己一开始是这么想的,如果用f[t][i][j]表示刷t次时 ...

  7. C++两种字符串传参构造函数

    第一种: #include"iostream" #include"string" using namespace std; class Motor{ prote ...

  8. Struts2学习(2)

    1.结果嗯配置 (1)全局结果页面 (2)局部结果页面 (3)result标签type属性 2.在action获取表单提交数据 (1)使用ActionContext类获取 (2)使用ServletAc ...

  9. js 实现自动调出键盘

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

  10. Memcache 笔记(2)

    一.Memcache概述出现的原因:随着数据量的增大,访问的集中,使得数据库服务器的负担加重,数据库响应恶化,网站显示延迟等 memcache:是高性能的分布式内存缓存服务器.通过缓存数据库的查询结果 ...