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

时间:2022-09-16 22:57:40

题目链接:http://poj.org/problem?id=2976

Dropping tests
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13615   Accepted: 4780

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

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

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 POJ2976 Dropping tests —— 01分数规划 二分法. However, if you drop the third test, your cumulative average becomes POJ2976 Dropping tests —— 01分数规划 二分法.

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

 
 
 
题解:
POJ2976 Dropping tests —— 01分数规划 二分法
 
 
 
 
代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e3+; int a[MAXN], b[MAXN];
double d[MAXN];
int n, k; bool test(double L)
{
for(int i = ; i<=n; i++)
d[i] = 1.0*a[i] - L*b[i];
sort(d+, d++n);
double sum = ;
for(int i = k+; i<=n; i++) //舍弃前k小的数
sum += d[i];
return sum>=;
} int main()
{
while(scanf("%d%d", &n, &k) && (n||k))
{
for(int i = ; i<=n; i++)
scanf("%d", &a[i]);
for(int i = ; i<=n; i++)
scanf("%d", &b[i]); double l = , r = 1.0;
while(l+EPS<=r)
{
double mid = (l+r)/;
if(test(mid))
l = mid + EPS;
else
r = mid - EPS;
}
printf("%.0f\n", r*);
}
}
 

POJ2976 Dropping tests —— 01分数规划 二分法的更多相关文章

  1. &lbrack;poj2976&rsqb;Dropping tests&lpar;01分数规划,转化为二分解决或Dinkelbach算法&rpar;

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

  2. POJ2976 Dropping tests&lpar;01分数规划)

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

  3. POJ2976 Dropping tests 01分数规划

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

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

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

  5. Dropping tests&lpar;01分数规划&rpar;

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

  6. POJ 2976 Dropping tests 01分数规划

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

  7. &dollar;POJ&dollar;2976 &dollar;Dropping&bsol; tests&dollar; 01分数规划&plus;贪心

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

  8. POJ - 2976 Dropping tests&lpar;01分数规划---二分&lpar;最大化平均值&rpar;&rpar;

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

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

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

随机推荐

  1. Vue&period;js:轻量高效的前端组件化方案

    转发一篇尤老师对vue.js的介绍,了解vue.js的来龙去脉.不过现在已经是2.0了,也有添加一些新的东西,当然有些东西也改了. Vue.js:轻量高效的前端组件化方案 Vue.js 是我在2014 ...

  2. linux 中的 tar 解压

    Type at the command prompt tar xvzf file-1.0.tar.gz - tgfo uncompress a gzip tar file (.tgz or .tar. ...

  3. SharePoint&bsol;O365 CSOM操作&quot&semi;请求访问设置&quot&semi;功能

    博客地址:http://blog.csdn.net/FoxDave 请求访问设置是在SharePoint网站权限菜单中的一个功能,如下图: 它用来设置成员是否可以共享网站以及个别文件和文件夹,是否允许 ...

  4. How to include cascading style sheets &lpar;CSS&rpar; in JSF

    In JSF 2.0, you can use <h:outputStylesheet /> output a css file. For example, <h:outputSty ...

  5. 跟我一起读postgresql源码&lpar;十五&rpar;——Executor&lpar;查询执行模块之——control节点&lpar;上&rpar;&rpar;

    控制节点 控制节点用于完成一些特殊的流程执行方式.由于PostgreSQL为査询语句生成二叉树状的査询计划,其中大部分节点的执行过程需要两个以内的输入和一个输出.但有一些特殊的功能为了优化的需要,会含 ...

  6. Android BottomNavigationBar导航栏

    基本属性 setActiveColor //选中item的字体颜色 setInActiveColor //未选中Item中的颜色 setBarBackgroundColor//背景颜色 setMode ...

  7. Android-Layer list

    Android-Layer list 学习自: KEEGAN小钢 原文链接 : (https://keeganlee.me/post/android/20150909) 使用layer-list 可以 ...

  8. java学习笔记-输入输出流

    ================File类 =====================InputStream ==================OutputStream ============== ...

  9. 压力测试Jmeter&plus;badboy

    压力测试Jmeter+badboy 前言:很多人都想学习压力测试,但是一开始手动写脚本着实蛋疼,所以今天我教大家的是利用badboy来录制压测脚本,然后用Jmeter来做压力测试. 流程:badboy ...

  10. List接口的实现类与ArrayList相似,区别是Vector是重量级的组件,使用使消耗的资源比较多

    List接口的实现类(Vector)(与ArrayList相似,区别是Vector是重量级的组件,使用使消耗的资源比较多.) 结论:在考虑并发的情况下用Vector(保证线程的安全). 在不考虑并发的 ...