[poj 2976]Dropping tests 01分数规划
来源:互联网 发布:加内特的生涯数据 编辑:程序博客网 时间:2024/05/21 19:38
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 15 0 25 1 64 21 2 7 95 6 7 90 0
Sample Output
83100
题目大意
手中有A场考试,每场考试答对的题目数为a[i],题目数为b[i],可以不计其中m场的结果,求答对题数/总题数的最大值
解题思路
01分数规划入门,算法来自http://www.cnblogs.com/perseawe/archive/2012/05/03/01fsgh.html
这个时候我们只需设d[i]=a[i]-b[i]*x,对于每一个x求sum{d[i]}是否大于0。
因为最优(最大)可行解只有一个,二分求解。
每次判断时只需要拿出d[i]最大的n-m个值即可。
code:
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath> #include <string>#define eps 1e-9using namespace std;int cmp(double x,double y){return x>y;}double a[1005];double b[1005];double d[1005];int n,m,k;int main(){while(~scanf("%d%d",&n,&m),n+m){for (int i=1;i<=n;i++)scanf("%lf",&a[i]);for (int i=1;i<=n;i++)scanf("%lf",&b[i]);double ma=1,mi=0;while (ma-mi>eps){double mid=(ma+mi)/2;for (int i=1;i<=n;i++)d[i]=a[i]-mid*b[i];sort(d+1,d+1+n,cmp);double check=0;for (int i=1;i<=n-m;i++)check+=d[i];if (check>=0) mi=mid;else ma=mid;}printf("%.0f\n",ma*100);}return 0;}
- POJ 2976 Dropping tests 01分数规划
- POJ 2976 Dropping tests 01分数规划
- poj-2976-Dropping tests-01分数规划
- POJ 2976 Dropping tests 01分数规划
- 【POJ】2976 Dropping tests 01分数规划
- [poj 2976]Dropping tests 01分数规划
- POJ 2976 Dropping tests (01分数规划)
- POJ 2976 Dropping tests(01分数规划)
- POJ - 2976 Dropping tests 01分数规划
- POJ 2976 Dropping tests 01分数规划
- POJ 2976- Dropping tests -01分数规划
- POJ 2976 Dropping tests 01分数规划
- poj 2976 Dropping tests 01分数规划
- POJ-2976:Dropping tests【01分数规划】
- POJ 2976:Dropping tests 01 分数规划
- POJ 2976 Dropping tests (01分数规划)
- POJ 2976 Dropping tests & 分数规划讲解
- poj Dropping tests 01分数规划
- hdu 1010 Tempter of the Bone(DFS)
- 集合框架(泛型限定2)
- OJ最长公共字串
- ThinkPHP实现文件伪静态
- ZOJ-1204
- [poj 2976]Dropping tests 01分数规划
- ActiveMQ_hello word
- 集合-Map概述-Map子类对象特点-Map共性方法
- Jquery
- OC冒泡排序
- 【大话QT之十六】使用ctkPluginFramework插件系统构建项目实战
- 关于enum { IDD = IDD_ADD };的使用
- POJ3071Football——概率动态规划+异或^的妙用
- Twisted 学习1