[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. Django进阶之查询优化、extra注入SQL及批量创建

    Django查询优化 Django的查询优化用到两个函数——select_related()和prefetch_related(). select_related()用的是连表join的方式,主要处理 ...

  2. ORACLE---OCP培训

    闪回恢复区 SYS@orcl>show parameter recov; NAME         TYPE  VALUE------------------------------------ ...

  3. int bool 字符串 列表 字典 集合

    1.int和bool 输出i的最大二进制位数inti = 1000 print(i.bit_length()) 2. str int bool list set dict  tuple 相互转换 pr ...

  4. Python基础学习之Python主要的数据分析工具总结

    Python主要是依靠众多的第三方库来增强它的数据处理能力的.常用的是Numpy库,Scipy库.Matplotlib库.Pandas库.Scikit-Learn库等. 常规版本的python需要在安 ...

  5. visual studio code常用插件

    1.auto close tag2.chinese language pack for visual studio code3.debugger for chrome4.docker5.html cs ...

  6. 擦他丫的,今天在Django项目中引用静态文件jQuery.js 就是引入报错,终于找到原因了!

    擦 ,今天在Django项目中引用静态文件jQuery.js 就是引入报错,终于找到原因了! 问题在于我使用的谷歌浏览器,默认使用了缓存,导致每次访问同一个url时,都返回的是缓存里面的东西.通过谷歌 ...

  7. protocol buffer简介

    一.protocol buffer简介 protocol buffer(简称PB)是google开源的一个数据序列化与反序列化工具,由于其支持多种语言.各种平台,多被用于对象的存储,远程调用等方向.用 ...

  8. c# 结构的使用

    类的定义的是引用类型,重点在堆上创建,有的时候类只包含极少的数据,因为管理堆而造成的开销是很大的.这时候更好的做法就是将类型定义成结构.结构是值类型,在栈上存储,能有效的减小内存管理的开销.c#基元类 ...

  9. 分布式系统Paxos算法

    转载 原地址:https://www.jdon.com/artichect/paxos.html 主要加一个对应场景,如:Spring Cloud 的 Consul 集权之间的通信,其实是Raft算法 ...

  10. Unable to construct api.Node object for kubelet: can't get ip address of node master.example.com: lookup master.example.com on : no such host

    openshift首页进不去 启动openshift时报的错,大意是: 无法为kubelet构造api.Node对象:无法获取节点master.example.com的IP地址: 所以就联想到新装的c ...