POJ——T 2976 Dropping tests
http://poj.org/problem?id=2976
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 13861 | Accepted: 4855 |
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 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).
Source
#include <algorithm>
#include <cstdio> inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const double eps(1e-);
const int N();
double a[N],b[N];
int n,k; double l,r,mid,ans,tmp[N];
inline bool check(double x)
{
double sum=0.0;
for(int i=; i<=n; ++i)
tmp[i]=1.0*b[i]*x-100.0*a[i];
std::sort(tmp+,tmp+n+);
for(int i=; i<=n-k; ++i) sum+=tmp[i];
return sum<;
} int Presist()
{
for(; ; )
{
read(n),read(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]);
for(l=,r=100.0; r-l>eps; )
{
mid=(l+r)/2.0;
if(check(mid))
l=mid;
else r=mid;
}
printf("%.0lf\n",l);
}
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}
POJ——T 2976 Dropping tests的更多相关文章
- POJ:2976 Dropping tests(二分+最大化平均值)
Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...
- 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 ...
- 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分数规划入门)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11367 Accepted: 3962 D ...
- 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 2976 Dropping tests (0/1分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4654 Accepted: 1587 De ...
- Poj 2976 Dropping tests(01分数规划 牛顿迭代)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n t ...
随机推荐
- AJPFX:如何保证对象唯一性呢?
思想: 1,不让其他程序创建该类对象. 2,在本类中创建一个本类对象. 3,对外提供方法,让其他程序获取这个对象. 步骤: 1,因为创建对象都需要构造函数初始化,只要将本类中的构造函数私有化,其他程序 ...
- 5.1点击4个按钮显示相应的div
事件:onclick 属性:display,className 用到for语句,index标记,this当前事件 先清空后附加 <!DOCTYPE html><html>< ...
- mui 时间日期控件(浏览器上无法查看,在手机端可以点击)
<head> <meta charset="utf-8"> <meta name="viewport" content=" ...
- 添加QScintilla时显示无法解析的外部函数
转载请注明出处:http://www.cnblogs.com/dachen408/p/7147165.html 问题:添加QScintilla时显示无法解析的外部函数 解决方案:去掉头文件qscisc ...
- C++模版完全解析
模版 模版在C++中是一个很重要的概练,生活中的模版也是随处可见,比如制造工程师会 哪一个模子去构造出一个一个的工件,C++程序员能够用模版去实例化y有相同操作 不同类型的函数或者数据结构.简单的理解 ...
- ALTER SEQUENCE - 更改一个序列生成器的定义
SYNOPSIS ALTER SEQUENCE name [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MA ...
- css 最高权重 !important;
border-top: 1px solid #ccc !important;
- dxf组码
值 说明 -5 APP:永久反应器链 -4 APP:条件运算符(仅与 ssget 一起使用) -3 APP:扩展数据 (XDATA) 标记(固定) -2 APP:图元名参照(固定) -1 APP:图元 ...
- C#线程锁使用全功略
C#线程锁使用全功略 前两篇简单介绍了线程同步lock,Monitor,同步事件EventWaitHandler,互斥体Mutex的基本用法,在此基础上,我们对 它们用法进行比较,并给出什么时候需要锁 ...
- 无插件纯Web 3D机房,HTML5+WebGL倾力打造
前言 最近项目开发任务告一段落,刚好有时间整理这大半年的一些成果.使用html5时间还不久,对js的认识还不够深入.没办法,以前一直搞java,对js的一些语言特性和概念一时还转换不过来. 上一篇大数 ...