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. requests.post处理Content-Type: multipart/form-data的请求

    前几天遇到一个需求,要调用一个接口发送请求,抓包之后得到的数据是这样的 上网看了一些资料得知,原来这个接口的数据是通过multipart/form-data格式传过去的,multipart/form- ...

  2. NSCoder

    person.h头文件内容 #import <Foundation/Foundation.h> @interface Person : NSObject { NSString *name; ...

  3. Request对象介绍(客户端到服务器)

    1.处理请求和响应的过程request,response,关于request可以从三个方面着手学习.1:如何获取请求头  行  体   2:请求中文处理     3:请求对象的其它常用方法 1.1:r ...

  4. thinkphp 多表事务处理

    try{ $this->user = D('User'); $this->user->startTrans(); //开始事务 $res = $this->user->S ...

  5. 字符在内存中最终的表示形式是什么?是某种字符编码还是码位(Code Point)?

    字符在内存中最终的表示形式是什么?是某种字符编码还是码位(Code Point)? 根据我的了解,编码中有三个核心概念:1. 字符集(Character Set),可以说是一个抽象概念,字符的合集2. ...

  6. Qt QSortFilterProxyModel示例代码, 使用方法

    1. QSortFilterProxyModel不能单独使用,它只是一个"代理",真正的数据需要另外的一个model提供,而且它是用来排序和过滤的. 2. 实现代码 #ifndef ...

  7. 微信内置浏览器http请求10秒内接收不到数据会自动重发第二遍请求

    微信内置浏览器http请求10秒内接收不到数据会自动重发第二遍请求     这是个坑

  8. Linux下DB2的TCP配置

    1切换到db2实例用户下(uppdb) su - uppdb 2查看db2是否开启tcp服务 db2set -all 设置tcp服务:db2set DB2COMM=TCPIP 3查看是否配置db2 t ...

  9. PHP的目录路径问题

    在windows下,可以用“/”或者“\”来表示目录层次,而linux下只能用“/”:同时在linux下没有盘符的概念,只有用“/”符号表示唯一的根目录.所以,用一个变量表示目录位置的话,用“/”最安 ...

  10. WPF TextBox 只能输入数字键

     <Grid>         <TextBox Name="textBox1" PreviewTextInput="textBox1_PreviewT ...