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. JAVAWeb学习总结(一)

    一.基本概念 1.1.WEB开发的相关知识 WEB,在英语中web即表示网页的意思,它用于表示Internet主机上供外界访问的资源. Internet上供外界访问的Web资源分为: 静态web资源( ...

  2. vector对象

    vector是模板而非类型,由vector生成的类型必须包含vector中元素的类型,例如vector<int> 定义和初始化vector对象: vector<T> v1    ...

  3. Mybatis细节问题

    1.将字符串转换为日期格式? @DateTimeFormat(pattern="yyyy-MM-dd")

  4. 算法总结之 在数组中找到出现次数 > N/K的数

    题目1 给定一个整型数组arr,  打印其中出现次数大于一半的数, 如果没有这样的数,打印提示信息 进阶 给定一个整型数组arr, 再给定一个整数K, 打印所有出现次数大于 N/K的数,如果没有这样的 ...

  5. 扩展KMP(转)

    拓展kmp是对KMP算法的扩展,它解决如下问题: 定义母串S,和字串T,设S的长度为n,T的长度为m,求T与S的每一个后缀的最长公共前缀,也就是说,设extend数组,extend[i]表示T与S[i ...

  6. C中的指针和字符串

    程序 #include<stdio.h>int main(void){ char *mesg="Don't be a fool!"; char *copy; copy= ...

  7. db2数据导出导入del与ixf格式区别

    之前做数据迁移的时候遇到乱码的一些坑,总结一下.  一般导入导出: db2 export to /home/xxxx.del of del select * from tablename db2 im ...

  8. phalcon:官方多模块支models层,mode数据库配置

    phalcon:官方多模块支models层,mode数据库配置 按: backend分后台, frondend 分前台 每个多模块下面都有一个 Module.php文件, 1. frondend/mo ...

  9. PowerDesigner15生成数据库 同时自动生成字段说明(备注)信息

    1.打开Database->Generate Database 2.切换到Format标签页,选中Generate name in empty comment即可生成每个字段的说明(备注)信息 ...

  10. deep learning (五)线性回归中L2范数的应用

    cost function 加一个正则项的原因是防止产生过拟合现象.正则项有L1,L2 等范数,我看过讲的最好的是这个博客上的:机器学习中的范数规则化之(一)L0.L1与L2范数.看完应该就答题明白了 ...