B - Dropping tests
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 npositive 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).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
#define eps 1e-7
int n,k;
double a[],b[],t[]; double gh(double x)
{
for(int i=;i<n;i++)
t[i]=a[i]-x*b[i];
sort(t,t+n);
double ans=;
for(int i=k;i<n;i++)
ans+=t[i];
return ans;
} int main()
{
while(scanf("%d %d",&n,&k))
{
if(n==&&k==) break;
for(int i=;i<n;i++)
scanf("%lf",&a[i]);
for(int i=;i<n;i++)
scanf("%lf",&b[i]);
double l=0.0,r=1.0,mid;
while(r-l>eps)
{
mid=(l+r)/;
if(gh(mid)>) l=mid;
else r=mid;
}
printf("%1.f\n",l*);
}
return ;
}
B - Dropping tests的更多相关文章
- POJ2976 Dropping tests(二分+精度问题)
---恢复内容开始--- POJ2976 Dropping tests 这个题就是大白P144页的一个变形,二分枚举x,对a[i]-x*b[i]从大到小进行排序,选取前n-k个判断和是否大于等于0,若 ...
- Dropping tests(01分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8176 Accepted: 2862 De ...
- POJ 2976 Dropping tests 01分数规划 模板
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6373 Accepted: 2198 ...
- POJ 2976 Dropping tests(01分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions:17069 Accepted: 5925 De ...
- [poj P2976] Dropping tests
[poj P2976] Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, ...
- POJ 2976 Dropping tests (0/1分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4654 Accepted: 1587 De ...
- HDU2976 Dropping tests 2017-05-11 18:10 39人阅读 评论(0) 收藏
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12187 Accepted: 4257 D ...
- 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
最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...
- 【POJ2976】Dropping Tests(分数规划)
[POJ2976]Dropping Tests(分数规划) 题面 Vjudge 翻译在\(Vjudge\)上有(而且很皮) 题解 简单的\(01\)分数规划 需要我们做的是最大化\(\frac{\su ...
随机推荐
- C# 数字转换成大写
/// <summary> /// 数字转大写 /// </summary> /// <param name="Num">数字</para ...
- CentOS 7 实现ssh无密码登录
cd ~ 进入根目录. (使用ls -a或者 ls -la 能够看到当前文件夹下的所有文件包含隐藏文件夹等) 我们首先使用ls -la 发现并没有.ssh的文件夹存在. 在终端输入 ssh lo ...
- jpg转yuv420抠图后转为jpg
最近遇到个需求,已有全景图和其中的人脸坐标,将人脸小图从全景图中抠出来,最开始使用libjpeg,奈何使用libjpeg将jpg转为yuv420的资料实在少,libjpeg自身的readme和exam ...
- 分布式计算课程补充笔记 part 4
▶ 并行通讯方式: map 映射 全局一到一 全局单元素计算操作 transpose 转置 一到一 单元素位移 gather 收集 多到一 元素搬运不计算 scatter 分散 一到多 元素搬运不计算 ...
- orcal 程序自动和手动项
orcal在电脑开机后,为了可以使用 这两个服务设置为自动(为了使用),其他设置为手动(减少电脑压力):
- HTML5 元素文字超出部分显示省略号(支持多行),兼容几乎所有常用浏览器
1,公共样式,在公共的 CSS 文件中加入以下内容 /* 超出部分显示省略号,支持多行 */ .text-ells:before { content: ''; float: left; width: ...
- Signals的使用(通知)
https://docs.djangoproject.com/en/2.1/topics/signals/
- 在delphi中XLSReadWriteII.组件的应用实例(2)
第三方组件:XLSReadWriteII.v.5.20.67_XE3 实例源码如下: unit Unit1; interface uses Winapi.Windows, Winapi.Messa ...
- 29.Hibernate-二级缓存和session管理.md
目录 1.概念 1.1一级缓存: 1.2二级缓存: 2.使用方法 3.策略 3.1缓存策略 3.2集合缓存 3.3查询缓存 5. Seesion管理 1.概念 Hibernate提供的缓存 有一级缓存 ...
- oracle 连接字符串的问题
未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息.数据类型不被支持. 原因是你用的ADO for ORACLE的驱动是微软的Microsoft OLE DB ...