Dropping tests
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8349   Accepted: 2919

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 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).

Source

 
分析:这道题目要是看了01规划,大水题一道,
 01规划:http://www.cnblogs.com/perseawe/archive/2012/05/03/01fsgh.html
  不过最后要注意的是因为要四舍五入,所以不能直接对整数二分,最后输出+0.005就是为了四舍五入
#include<cstdio>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
struct Node{
int a,b;
double temp;
}node[1005];
int n,k;
bool cmp(Node a ,Node b)
{
return a.temp>b.temp;
}
int ok(double mid)
{
for(int i=1;i<=n;i++)
node[i].temp=node[i].a*1.0-mid*node[i].b;
sort(node+1,node+n+1,cmp);
double sum=0;
for(int i=1;i<=n-k;i++)
sum+=node[i].temp;
return sum>=0;
}
int main()
{
while(~scanf("%d %d",&n,&k))
{
if(n==0&&k==0) return 0;
for(int i=1;i<=n;i++)
scanf("%d",&node[i].a);
for(int i=1;i<=n;i++)
scanf("%d",&node[i].b);
double l=0,r=1,mid;
while(r-l>1e-5)
{
mid=(l+r)/2;
if(ok(mid))
l=mid;
else
r=mid;
}
printf("%d\n",int(100*(l+0.005))); //四舍五入
}
return 0;
}

  

poj 2976 Dropping tests 二分搜索+精度处理的更多相关文章

  1. poj 2976 Dropping tests (二分搜索之最大化平均值之01分数规划)

    Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...

  2. POJ - 2976 Dropping tests && 0/1 分数规划

    POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...

  3. 二分算法的应用——最大化平均值 POJ 2976 Dropping tests

    最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...

  4. POJ 2976 Dropping tests 【01分数规划+二分】

    题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  5. POJ 2976 Dropping tests(01分数规划入门)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11367   Accepted: 3962 D ...

  6. POJ 2976 Dropping tests 01分数规划 模板

    Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 ...

  7. POJ 2976 Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:17069   Accepted: 5925 De ...

  8. POJ 2976 Dropping tests (0/1分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4654   Accepted: 1587 De ...

  9. Poj 2976 Dropping tests(01分数规划 牛顿迭代)

    Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n t ...

随机推荐

  1. 四则运算计算器的微信小程序_1 界面

    主界面wxml文件: page{ height:100%; } .content{ min-height:100%; display:flex; flex-direction:column; alig ...

  2. ZooKeeper的ACL权限

    ACL控制权限 什么是ACL(Access Control List访问控制列表) 针对节点可以设置相关读写等权限, 目的为了保障数据安全性 权限permission可以指定不同的权限范围以及角色 A ...

  3. ABC136E Max GCD

    Thinking about different ways of thinking. --- LzyRapx 题目 思路比较容易想到. Observations: 每次操作过后和不变. 枚举和的因子 ...

  4. C++多线程基础学习笔记(八)

    shared_futrue和futrue_status的用法 shared_futrue是一个类模板,类似于futrue,不同的是它的成员函数get()可以使用多次,因为是复制数据,而futrue的g ...

  5. win10 远程桌面ubuntu16

    一. 软件安装 1.1. 打开终端,安装xrdp,vncserver sudo apt-get install xrdp vnc4server xbase-clients 1.2. desktop s ...

  6. ZOJ 2314 (无源汇有上下边界的可行流)

    (点击此处查看原题) 题意分析 给出n个结点,m条管道,每条管道存在最小流量和最大流量,而且每个结点的流入量等于流出流出量,问这n个结点和m条管道能否形成流量循环 解题思路 经典的无源汇有上下边界的可 ...

  7. CSS3鼠标悬停翻转按钮

    在线演示 本地下载

  8. 从尾到头打印列表——牛客剑指offer

    题目描述 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 解题思路 思路1: 顺序遍历链表,取出每个结点的数据,插入list中. 由于要求list倒序存储链表中的数据,而我们是顺序取 ...

  9. 前端 使用localStorage 和 Cookie相结合的方式跨页面传递参数

    A页面 html代码: 姓名:<input type="text" id="name1"> 年龄:<input type="text ...

  10. node.js学习之路(1)

    node.js 属于后台语言,后台语言还有php,java等. 优势:1.性能好   node.js VS php   86倍 2.跟前台JS配合方便 3.node.js便于前端学习 https:// ...