[poj P2976] Dropping tests

Time Limit: 1000MS  Memory Limit: 65536K

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

Hint

To avoid ambiguities due to rounding errors, the judge tests have been constructed so that all answers are at least 0.001 away from a decision boundary (i.e., you can assume that the average is never 83.4997).

Source

01分数规划入门题。

这个不等式会经常看到:sigma(ai)/sigma(bi)>=(或<=)k

对于这题来说就是,找出最大的k,使得100*sigma(ai)/sigma(bi)>=k。

我们尝试化简上式。

因为bi>=0,所以sigma(bi)>=0,100*sigma(ai)>=k*sigma(bi)

100*sigma(ai)-k*sigma(bi)>=0

sigma(100*ai-k*bi)>=0

那么,我们只要先枚举一个k,将100*ai-k*bi作为关键字排序,再选出前n-k大的,判断一下sum是否非负就行了。

然后我们发现,上式满足单调性,枚举可以改为用二分。所以总复杂度是O(nlog分数)。

然后这一题我先开大100倍,然后最后再缩小100倍,但是这也会有精度误差。

总之,开大的倍数越大,误差越小,但效率越低,但也低不到哪里去qwq

code:

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 #define LL long long
 #define M ((L)+(R)>>1)
 using namespace std;
 ,lim=;
 int n,k,L,R,ans,final; LL sum;
 struct ob {LL a,b,c;}o[N];
 bool cmp(ob x,ob y) {return x.c>y.c;}
 bool jug(LL lv) {
     ; i<=n; i++) o[i].c=o[i].a*lim-lv*o[i].b;
     sort(o+,o++n,cmp);
     sum=;
     ; i<=n-k; i++) sum+=o[i].c;
     ;
 }
 int main() {
     while (scanf("%d%d",&n,&k)!=EOF,n|k) {
         ; i<=n; i++) scanf("%lld",&o[i].a);
         ; i<=n; i++) scanf("%lld",&o[i].b);
         ,R=lim; L<=R; )
             ;
             ;
         final=ans/; ans%=;
         ) final+=;
         printf("%d\n",final);
     }
     ;
 }

[poj P2976] Dropping tests的更多相关文章

  1. POJ - 2976 Dropping tests && 0/1 分数规划

    POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...

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

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

  3. POJ 2976 Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:17069   Accepted: 5925 De ...

  4. POJ 2976 Dropping tests 【01分数规划+二分】

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

  5. POJ 2976 Dropping tests(01分数规划入门)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11367   Accepted: 3962 D ...

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

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

  7. POJ 2976 Dropping tests (0/1分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4654   Accepted: 1587 De ...

  8. Poj 2976 Dropping tests(01分数规划 牛顿迭代)

    Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n t ...

  9. poj 2976 Dropping tests 二分搜索+精度处理

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8349   Accepted: 2919 De ...

随机推荐

  1. C#编程基础(简单概述与理解)

    1.C#变量和数据输入 C#常用到的几个数据类型: 整型:int 说明:32位有符号整数 范围:-2³¹~2³¹-1 浮点型:double 说明:64位双精度浮点数 范围:±5.0×10-­﹣³²~± ...

  2. 选择排序(Python实现)

    目录 1. for版本--选择排序 2. while版本--选择排序 3.测试用例 4. 算法时间复杂度分析 1. for版本--选择排序 def select_sort_for(a_list): ' ...

  3. 深入理解Java虚拟机1-chap1-2-斗之气8段

    1.HotSpot VM:热点代码探测能力,与JIT技术共同进行编译优化,输出高质量代码 2.运行时数据区域 程序计数器:控制程序执行顺序,无OOM Java虚拟机栈:生命周期与线程一致,描述Java ...

  4. egg.js基础入门

    之前一直使用koa, 刚刚接触egg, 做了一些入门的笔记 准备工作 1  首先安装脚手架,,并创建项目. $ npm i egg-init -g $ egg-init egg-demo --type ...

  5. 百度富文本Ueditor编辑器的使用

    往在web开发的时候,尤其是在网站开发后台管理系统的时候经常会使用到富文本编辑器,这里我们来使用百度提供的富文本编辑器UEditor,以提高我们的开发效率 UEditor官网下载地址:https:// ...

  6. 服务注册发现Eureka

    一 Eureka相关概念 1 Peer   2 Zone   3 Region 地理区域   3 CAP理论   4 在线扩容   5     二 注册发现 Eureka 1 搭建Server服务端 ...

  7. 关于PChar(@string)的疑惑

    看到一篇博客关于讲Delphi中MOVE的例子,心生疑惑.记录下自己的实验,虽然我也不知道这是啥... program Project1; {$APPTYPE CONSOLE} uses SysUti ...

  8. Bamboo基础概念

    1.project     1)提供报告.展板.连接   |——2.plan       1)指定默认代码仓库(同一个仓库)       2)构建触发条件的配置       3)构建结果的发送与通知 ...

  9. 给datagrid的日期格式化成年月日

    $('#infos').datagrid({ title:'系统版本列表', iconCls:'icon-view', method:'POST', singleSelect:false, fit : ...

  10. json字符串 转Java List 简单方法

    JSONArray jsonArr = JSONArray.fromObject(jsonStr); List<Map<String,Object>> listMap = (L ...