POJ:2976 Dropping tests(二分+最大化平均值)
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 aifor 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).
题意:有N个考试,每个考试有ai和bi两个值,最后成绩由上面的公式求得。幸运的是,可以放弃K个科目,求最大化最后的成绩。
思路:这是一道简单的最大化平均值模板题,化简出(ai-mid*bi)>0,求n-k前项。
AC代码:
#include<stdio.h>
#define INF 0x3f3f3f3f
#include<algorithm>
using namespace std;
bool cmp(double x,double y)
{
return x>y;
}
int n,k;
double y[];
int a[];
int b[];
bool C(double mid)
{
for(int i= ; i<n ; i++)
{
y[i]=a[i]-mid*b[i];
}
sort(y,y+n,cmp);
double sum=;
for(int i= ; i<n-k ; i++)
{
sum+=y[i];
}
if(sum>=)
return true;
return false;
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
if(n==&&k==)
break;
for(int i= ; i<n ; i++)
scanf("%d",&a[i]);
for(int i= ; i<n ; i++)
scanf("%d",&b[i]);
double st=,en=INF;
for(int i= ; i<= ; i++)
{
double mid=(st+en)/;
if(C(mid))
st=mid;
else
en=mid;
} printf("%.0f\n",st*);
}
}
POJ:2976 Dropping tests(二分+最大化平均值)的更多相关文章
- POJ 2976 Dropping tests (最大化平均值)
题目链接:click here~~ [题目大意]给你n个分数的值,要求最小不选k个,使得最后分数相加结果平均值最大 [解题思路]:最大化平均值:參见:click here~~ 代码: #include ...
- POJ 2976 Dropping tests(最大化平均值 or 01整数规划)
题目链接 忽略运算符逻辑导致奇怪的错误(代码中指明位置了) 输出没加0.5,WA. 还有,注意特殊情况k=0,所以scanf("%d%d", &n, &k)& ...
- POJ 2976 3111(二分-最大化平均值)
POJ 2976 题意 给n组数据ai,bi,定义累计平均值为: 现给出一个整数k,要求从这n个数中去掉k个数后,最大累计平均值能有多大?(四舍五入到整数) 思路 取n−k个数,使得累计平均值最大. ...
- POJ 2976 Dropping tests [二分]
1.题意:同poj3111,给出一组N个有价值a,重量b的物品,问去除K个之后,剩下的物品的平均值最大能取到多少? 2.分析:二分平均值,注意是去除K个,也就是选取N-K个 3.代码: # inclu ...
- POJ 2976 Dropping tests (二分+贪心)
题意:给定 n 个分数,然后让你去年 m 个分数,使得把剩下的所有的分子和分母都相加的分数最大. 析:这个题并不是分子越大最后结果就越大,也不是整个分数越大,最后结果就越大的,我们可以反过来理解,要去 ...
- 二分算法的应用——最大化平均值 POJ 2976 Dropping tests
最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...
- POJ - 2976 Dropping tests && 0/1 分数规划
POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...
- POJ 2976 Dropping tests 【01分数规划+二分】
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))
题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...
随机推荐
- JAVA中string类的split方法
split([separator,[limit]])第一个参数为分隔符,可以是一个正则表达式,第二个参数为返回结果数组的长度
- 【总结整理】行内标签span设置position:absolute/float属性可以设置宽度与高度
postion:absolute 跳出文本流,不是行内元素,设置宽高有效,我的理解. 引用下曹刘阳写的<编写高质量代码-web前端开发修炼之道>一书中看到的一句话:position:abs ...
- 使用Java建立聊天客户端
---------------siwuxie095 关于 聊天服务器,详见本人博客的分类:来一杯Java, 里面的 使用ServerSocket ...
- phper 需要学习js
- SpringBoot05 数据操作02 -> JPA接口详解
概览 JpaRepository 继承 PagingAndSortingRepository 继承 CrudRepository 继承 Repository 1 Repository 这是一个空接口, ...
- 生产者与消费者-1:N-基于list
一个生产者/多个消费者: /** * 生产者 */ public class P { private MyStack stack; public P(MyStack stack) { this.sta ...
- Configuration File (php.ini) Path Loaded Configuration File 都有加载php.ini文件,有什么不同的地方?
Configuration File (php.ini) Path /usr/local/php7/etc 这个目录下面也有php.ini文件(如果在编译./configure -with- ...
- 使用RSS提升DPDK应用的性能(转)
本文描述了RSS以及在DPDK中如何配置RSS达到性能提升和统一分发. 什么是RSS RSS(Receive Side Scaling)是一种能够在多处理器系统下使接收报文在多个CPU之间高效分发的网 ...
- CLRInjection - 通用托管注入(超级灰色按钮克星升级版)
通用托管注入 - CLRInjection CLR软件系列第二发: 通用托管注入 - CLRInjection 软件简介:这款软件可以将任意托管DLL用插件的形式,注入到正在运行中的.net托管程序集 ...
- 《Effective Java》第6章 枚举和注解
第30条:用enum代替int常量 将加班工资计算移到一个私有的嵌套枚举中,将这个策略枚举(strategy enum)的实例传到PayrollDay枚举的构造器中.之后PayrollDay枚举将加班 ...