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. linux centos7.3安装lnmp,nginx-1.11.12 ,php7.0.2 ,

    #更新源 yum -y update #添加用户和组 adduser www groupadd www usermod -G www www #初始化目录 mkdir -p /data/app/php ...

  2. 使用Keras基于RCNN类模型的卫星/遥感地图图像语义分割

    遥感数据集 1. UC Merced Land-Use Data Set 图像像素大小为256*256,总包含21类场景图像,每一类有100张,共2100张. http://weegee.vision ...

  3. jQuery俄罗斯方块游戏动画

    在线演示       本地下载

  4. redis 学习(11)-- redis pipeline

    redis pipeline 什么是流水线(pipeline) 首先来看 redis 执行一次操作所需要的时间: 1 次时间 = 1 次网络时间 + 1次命令时间 执行 n 次就需要: n 次时间 = ...

  5. Mysql8.0安装与配置

    最近公司在开发项目时用到了mySql8.0版本,总结出了安装步骤,供需要的开发人员来参考 安装mySql8.0的步骤: 1.先去官网下载mySql8.0版本的安装包 一. 点击:https://dev ...

  6. 关于this关键字

    首先看一下这篇博客介绍:http://blog.csdn.net/ccpat/article/details/44515335 下面贴段代码 package com.xujingyang.test; ...

  7. SSD学习笔记

    目标检测算法——SSD:Single Shot MultiBox Detector,是一篇非常经典的目标检测算法,十分值得阅读和进行代码复现,其论文地址是:https://arxiv.org/abs/ ...

  8. jieba:我虽然结巴,但是我会分词啊

    介绍 jieba目前是一款比较好分词模块 分词 import jieba # 可以使用jieba.cut进行分词 sentence = "失去恋人所带来的苦痛远远超过了他的承受范围" ...

  9. Java入门指南-04 顺序、分支、循环

    顺序结构 从上至下,依次执行 if 语句在 Java 里,用 if 语句来实现“当满足 XXX 条件时,执行 YYY”这样的逻辑判断.例如,在使用共享单车时需要检查人的年纪.如果在 12 岁以下,则禁 ...

  10. 网上搜到的特别厉害的visio2019激活方法

    原文链接:https://blog.csdn.net/godot06/article/details/94141854 步骤如下: 1.电脑新建一个记事本文件.txt(任何地方都可以) 2.复制下面代 ...