[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. fat32转ntfs命令

    1.打开电脑左下角的 “开始” 菜单2.鼠标左键单机 “运行”3.弹出横框输入 cmd 后,确定4.弹出黑框输入 convert E:/FS:NTFS 然后回车5.提示输入盘符名,也就是你输入D盘的名 ...

  2. expect-调试模式的使用

    1.expect简介 Expect是一种TCL扩展性的语言,主要用于完成系统交互方面的功能,比如SSH.FTP等,这些程序都需要手工与它们进行互动,而使用Expect就可以模拟人手工互动的过程,是一种 ...

  3. 【Java】NO.80.Note.1.Java.1.001-【Java 各种特性概念】

    1.0.0 Summary Tittle:[Java]NO.80.Note.1.Java.1.001-[Java 各种特性概念] Style:Java Series:Java Since:2018-0 ...

  4. 【UML】NO.52.EBook.5.UML.1.012-【UML 大战需求分析】- 交互概览图(Interaction Overview Diagram)

    1.0.0 Summary Tittle:[UML]NO.52.EBook.1.UML.1.012-[UML 大战需求分析]- 交互概览图(Interaction Overview Diagram) ...

  5. Kestrel:Net Core的跨平台服务器

    概述 Kestrel是一个基于libuv的跨平台ASP.NET Core web服务器,libuv是一个跨平台的异步I/O库.ASP.NET Core项目默认使用Kestrel作为web服务器. 用户 ...

  6. centos----------centos下如何安装phpstorm

    1.首先打开centos下的谷歌浏览器,找到phpstorm官网下载linux版本.PhpStorm-2016.3.2.tar.gz 2.然后gunzip PhpStorm-2016.3.2.tar. ...

  7. EasyUI中使用textbox赋值,setValue和setText顺序问题

    注意两点: 当text和value的值不同时,一定要先赋值Value,然后赋值Text,否则text和value全部为Value的值. 如果只setValue,则使用getText和getValue得 ...

  8. vue项目初始化时npm run dev报错webpack-dev-server解决方法

    vue项目初始化时npm run dev报错webpack-dev-server解决方法 原因:这是新版webpack存在的BUG,卸载现有的新版本webpack,装老版本就好webpack-dev- ...

  9. js 图片无缝滚动

    html部分 <div id="roll"> <a href="javascript:void(0)" class="prev&qu ...

  10. 【Bcftools】合并不同sample的vcf文件,通过bcftools

    通过GATK calling出来的SNP如果使用UnifiedGenotype获得的SNP文件是分sample的,但是如果使用vcftools或者ANGSD则需要Vcf文件是multi-sample的 ...