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 ...
随机推荐
- leetcode20:有效的括号
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被认 ...
- ORACLE_11G归档空间满,由于数据库装完后使用的是默认空间是闪回区
1.首先根据alert跟踪日志发现归档空间满,路径大致如下:cd $ORACLE_BASE/diag/rdbms/jsswgsjk/jsswgsjk1/tracetail -f alert_jsswg ...
- 《算法导论》——随机化快排RandomizedQuickSort
今日算法:随机化快排RandomizedQuickSort 基础工作swap交换和partition分治 /* *交换数组的两个元素 *fromIndex和toIndex为要交换的两个元素的索引 */ ...
- 《面向对象程序设计(java)》第七周学习总结
1.实验目的与要求 (1)进一步理解4个成员访问权限修饰符的用途: (2)掌握Object类的常用API用法: (3)掌握ArrayList类用法与常用API: (4)掌握枚举类使用方法: (5)结合 ...
- leetcode494
public class Solution { public int FindTargetSumWays(int[] nums, int S) { Queue<int> Q = new Q ...
- pytho学习笔记---编码
编解码 ASCII:1字节,0-255 GBK2313:常用的汉字,2万多个 GBK:对GBK2313的补充,支持藏文,2个字节表示一个汉字 big5:台湾,繁体字 unicode:万国码,2-4字节 ...
- git保存用户名和密码
git保存用户名和密码 简介:tortoiseGit(乌龟git)图形化了git,我们用起来很方便,但是我们拉取私有项目的时候,每次都要输入用户名和密码很麻烦,这里向大家介绍怎么避免多少输入 试验环境 ...
- 通过windows远程桌面连接CentOS系统
前提: CentOS安装桌面,如果无桌面,请执行 # yum -y groups install "GNOME Desktop" # startx 1 2 配置源 # yum in ...
- 使用__slots__节省python内存技巧
__slots__作用 __slots__有一个作用是:限制类实例绑定的属性,但是它有一个更重要的作用就是节省内存,当然更适用于数据量大的情况(万量级以上). __slots__节省内存的原理 cla ...
- 算法练习LeetCode初级算法之树
二叉树的前序遍历 我的解法:利用递归,自底向下逐步添加到list,返回最终的前序遍历list class Solution { public List<Integer> preorderT ...