Dropping tests
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8176   Accepted: 2862

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个数后

的最大值;01分数规划;

代码:

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=;
struct Node{
int a,b;
};
Node dt[MAXN];
double d[MAXN];
int n,k;
bool fsgh(double R){
double sum=;
for(int i=;i<n;i++)d[i]=dt[i].a-R*dt[i].b;
sort(d,d+n);
for(int i=n-;i>=n-k;i--)sum+=d[i];
return sum>?true:false;
}
double erfen(double l,double r){
double mid;
while(r-l>1e-){
mid=(l+r)/;
if(fsgh(mid))l=mid;
else r=mid;
}
return mid;
}
int main(){
while(scanf("%d%d",&n,&k),n|k){
double mx=;
k=n-k;
for(int i=;i<n;i++)scanf("%d",&dt[i].a);
for(int i=;i<n;i++)scanf("%d",&dt[i].b),mx=max(1.0*dt[i].a/dt[i].b,mx);
printf("%.0f\n",erfen(,mx)*);
}
return ;
}

Dropping tests(01分数规划)的更多相关文章

  1. POJ 2976 Dropping tests 01分数规划 模板

    Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 ...

  2. POJ 2976 Dropping tests 01分数规划

    给出n(n<=1000)个考试的成绩ai和满分bi,要求去掉k个考试成绩,使得剩下的∑ai/∑bi*100最大并输出. 典型的01分数规划 要使∑ai/∑bi最大,不妨设ans=∑ai/∑bi, ...

  3. [poj2976]Dropping tests(01分数规划,转化为二分解决或Dinkelbach算法)

    题意:有n场考试,给出每场答对的题数a和这场一共有几道题b,求去掉k场考试后,公式.的最大值 解题关键:01分数规划,double类型二分的写法(poj崩溃,未提交) 或者r-l<=1e-3(右 ...

  4. $POJ$2976 $Dropping\ tests$ 01分数规划+贪心

    正解:01分数规划 解题报告: 传送门! 板子题鸭,,, 显然考虑变成$a[i]-mid\cdot b[i]$,显然无脑贪心下得选出最大的$k$个然后判断是否大于0就好(,,,这么弱智真的算贪心嘛$T ...

  5. POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))

    题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...

  6. POJ2976 Dropping tests —— 01分数规划 二分法

    题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. POJ2976 Dropping tests(01分数规划)

    题意 给你n次测试的得分情况b[i]代表第i次测试的总分,a[i]代表实际得分. 你可以取消k次测试,得剩下的测试中的分数为 问分数的最大值为多少. 题解 裸的01规划. 然后ans没有清0坑我半天. ...

  8. 【POJ2976】Dropping tests - 01分数规划

    Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...

  9. POJ2976 Dropping tests 01分数规划

    裸题 看分析请戳这里:http://blog.csdn.net/hhaile/article/details/8883652 #include<stdio.h> #include<a ...

随机推荐

  1. 浅谈Qt事件的路由机制:鼠标事件

    请注意,本文是探讨文章而不是教程,是根据实验和分析得出的结果,可能是错的,因此欢迎别人来探讨和纠正. 这几天对于Qt的事件较为好奇,平时并不怎么常用,一般都是用信号,对于事件的处理,一般都是需要响应键 ...

  2. 3n+1

    #include<iostream> using namespace std; int main() { int n; while(cin>>n) { int count=0; ...

  3. 在ProgressBar上加文字----显示百分比的进度条

    http://www.cnblogs.com/3dant/archive/2011/04/25/2026776.html

  4. CSS3 旋转 太阳系

    参考https://www.tadywalsh.com/web/cascading-solar-system/ 首先 旋转有两种方式  一种是使用 transform-origin  另一种是tran ...

  5. ElaticSearch网站

    http://www.tuicool.com/articles/r2QJVr http://so.searchtech.pro/articles/2013/06/16/1371392427213.ht ...

  6. ora-01653: unable to extend table sys.aud$ by 8192 in tablespac system[转载]

    在用sqlplus user/password@truth登录数据库时报如下错误:ORA-00604: error occurred at recursive SQL level 1ORA-01653 ...

  7. POJ 3294 Life Forms(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=3294 [题目大意] 求出在至少在一半字符串中出现的最长子串. 如果有多个符合的答案,请按照字典序输出. [题解] 将所有的字符串通 ...

  8. Is it possible to implement a Firebug-like “inspect element” DOM element highlighter with client-side JavaScript?

    Is it possible to implement a Firebug-like "inspect element" DOM element highlighter with ...

  9. Java图形化界面设计——中间容器(Jpanel)

    1.  将组件添加到JFrame中 方式之一: frame.getContentPane().add(childComponent) 用getContentPane()方法获得JFrame的内容面板, ...

  10. php在apache中运行模式

    php在apache中运行模式 (2011-12-18 02:38:27) 标签: 杂谈 分类: 服务器及软件 一.php在php在三种工作方式:Apache 模块DLL) 以下分别比较: 1. ph ...