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 ...
随机推荐
- Tomcat源码分析----eclipse中搭建源码环境
前提:JDK,至少1.7,ant,要设置ANT_HOME环境变量,需要再classpath中增加ant的lib目录,在path变量中增加ant的bin目录 1.官网下载tomcat源码包:apache ...
- openmv第一次调试
2018-09-19 20:14:51 import sensor, image, time import car import json import time from pyb import U ...
- idea下关联spark源码环境(转)
0.环境: java 1.8 scala 2.11.8 maven 3.5.0 idea 2017 spark 2.2.0 1完成以下配置 java环境变量 scala环境变量 maven setti ...
- [小记]Android缓存问题
今天晚上,产品经理打电话说我们的Android App除了问题,问题很简单就是一个缓存问题,由于这个程序是前同事写的,我也只能呵呵一笑,有些事你就得扛.还是回到正题吧,这个缓存问题,实在有点奇葩,所以 ...
- iOS:swift :可选类型
import UIKit /*: 可选类型 * 可选类型表示变量可以有值, 也可以没有值 * C 和 Objective-C 中并没有可选类型这个概念 * Swift中只有可选类型才可以赋值为nil ...
- RequireJS 上手使用
首先 点击此处 得到requirejs. 捣鼓了俩小时终于运行成功了,原因是因为require(['我是空格underscore',...],function(){...})的时候 变量多个空格(坑爹 ...
- Ryubook_1_switch_hub_部署执行
一.环境: mininet.ovs.Ryu. 二.实验过程: 1.搭建拓扑: 执行sudo mn --topo single,3 --mac --switch ovsk --controller re ...
- MFC_简易文件管理器
练习_简易文件管理器 Edit1编辑框绑定变量,初始化内容 m_EditCtrl = L"D:\"; 添加List控件,属性设置report,OnInitDialog()函数里添加 ...
- Seating Arrangement
1997: Seating Arrangement Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 543 Solved: ...
- 三、spring中高级装配(1)
大概看了一下第三章的内容,我从项目中仔细寻找,始终没有发现哪里有这种配置,但是看完觉得spring还有这么牛B的功能啊,spring的厉害之处,这种设计程序的思想,很让我感慨... 一.环境与prof ...