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.

题目大意

给出$n$个$a$和$b$,让选出$n-k$个使得$\frac{\sum a_i}{\sum b_i}$最大

思路

题目要求 $\frac{\sum a_i}{\sum b_i} \geq x$,$x$的最大值 ,也就是$\sum a_i - x \sum b_i \geq 0$ 二分完把$a_i-x b_i$排序取$n-k$个大的即可

/************************************************
*Author : lrj124
*Created Time : 2018.09.28.20:35
*Mail : 1584634848@qq.com
*Problem : poj2976
************************************************/
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn = 1000 + 10;
int n,k,a[maxn],b[maxn];
double tmp[maxn];
inline bool check(double x) {
for (int i = 1;i <= n;i++) tmp[i] = a[i]-x*b[i];
sort(tmp+1,tmp+n+1);
double ans = 0;
for (int i = k+1;i <= n;i++) ans += tmp[i];
return ans >= 0;
}
int main() {
while (cin >> n >> k) {
if (!n && !k) break;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= n;i++) cin >> b[i];
double l = 0,r = 0x3f3f3f3f;
while (fabs(r-l) >= 1e-6) {
double mid = (l+r)/2;
if (check(mid)) l = mid;
else r = mid;
}
int ans = int(l*100+0.5);
printf("%d\n",ans);
}
return 0;
}

【POJ2976】Dropping tests - 01分数规划的更多相关文章

  1. [poj2976]Dropping tests(01分数规划,转化为二分解决或Dinkelbach算法)

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

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

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

  3. POJ2976 Dropping tests(01分数规划)

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

  4. POJ2976 Dropping tests 01分数规划

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

  5. Dropping tests(01分数规划)

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

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

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

  7. POJ 2976 Dropping tests 01分数规划

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

  8. $POJ$2976 $Dropping\ tests$ 01分数规划+贪心

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

  9. POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))

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

随机推荐

  1. scratch编程体感游戏

    体感游戏有很多种,最常见的就是摄像头和声控了,今天我们要用scratch编写一系列的体感游戏!!!是不是很激动呢? 首先我们来编摄像头类的: No.1拳头打幽灵 挥动头就能打到幽灵了哟! 具体程序如下 ...

  2. Zuul原理

    @EnableZuulProxy和@EnableZuulServer @EnableZuulProxy和@EnableZuulServer通过实例化不同的Marker,走不同的AutoConfigur ...

  3. C++与正则表达式入门

    什么是正则表达式? 正则表达式是一组由字母和符号组成的特殊文本, 当你想要判断许多字符串是否符合某个特定格式:当你想在一大段文本中查找出所有的日期和时间:当你想要修改大量日志中所有的时间格式,在这些情 ...

  4. 【Nginx】并发量太高,Nginx扛不住?这次我错怪Nginx了!!

    写在前面 最近,在服务器上搭建了一套压测环境,不为别的,就为压测下Nginx的性能,到底有没有传说中的那么牛逼!具体环境为:11台虚拟机,全部安装CentOS 6.8 64位操作系统,1台安装部署Ng ...

  5. MySQL之表关系与范式

    关系: 所有的关系都是指表与表之间的关系. 将实体与实体的关系,反应到最终数据库表的设计上来,可以将关系分成三种:一对一,一对多(多对一)和多对多. 一对一: 一张表的一条记录一定只能与另外一张表的记 ...

  6. Centos 7 下安装PHP7.2(与Apache搭配的安装方式)

    (1)源码包下载 百度云下载地址:https://pan.baidu.com/s/1xH7aiGYaX62wij4ul5P-ZQ 提取码:m9zc (2)安装php依赖组件: yum -y insta ...

  7. Glide:重新加载失败的问题

    Glide在url不变,内容改变的时候重新加载还会显示第一张图片, 解决方法: https://blog.csdn.net/u013420865/article/details/53197788?de ...

  8. LQB2013A04倒置的标签

    这个题,一开始犯了一个很幼稚的错误 贴贴代码 #include<iostream> #include<stdio.h> #include<stdlib.h> #in ...

  9. excel文件双击打开空白

    excel文件双击打开之后进入软件,没有去读文件 一.现象描述 打开现象如下所示,只有excel模板,看不到excel中的表格模板. 二.想要打开文件 (1)在软件的文件--->打开--> ...

  10. numpy第三方库

    # 导入numpy 并赋予别名 np import numpy as np # 创建数组的常用的几种方式(列表,元组,range,arange,linspace(创建的是等差数组),zeros(全为 ...