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

 
 
题意:给出n个物品,每个物品有两个属性a和b,选择n-k个元素,询问sum{ai}/sum{bi}的最大值。
分数规划 二分答案ans , 判断 sum[a[i]]/sum[b[i]]与ans的关系
  即 判断 b[i]*ans-a[i]*100+b[i+1]*ans-a[i+1]*100+...+b[i+k]*ans-a[i+k]*100<0
 #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的更多相关文章

  1. POJ:2976 Dropping tests(二分+最大化平均值)

    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. Android ImageView setImageBitmap 不显示图片

    从sd卡里读出图片后有时调用setImageBitmap(bitmap)方法会显示不出图片,仔细考虑过后原来是加载的图片过大导致的,解决办法为: BitmapFactory.Options op = ...

  2. 【PostgreSQL-9.6.3】Red Hat 4.4.7下的安装

    1. 下载源码包https://www.postgresql.org/ftp/source/v9.6.1/ 2. 上传到/opt目录下 3. 创建postgres用户及dba组,并修改压缩包的属主属组 ...

  3. [Windows Server 2008] 搭建数据云备份

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:如何搭建数 ...

  4. http 1.0 http 1.1 http 2.0的区别

    HTTP/1.0 版的主要缺点是,每个TCP连接只能发送一个请求.发送数据完毕,连接就关闭,如果还要请求其他资源,就必须再新建一个连接. http1.1优点: 1.HTTP 1.1 版引入了持久连接( ...

  5. hibernate5.3版本出现hibernate中The server time zone value“乱码”问题的解决办法。

    <!-- 配置关于数据库连接的四个项 driverClass url username password --> <property name="hibernate.con ...

  6. python beautifulsoup获取特定html源码

    beautifulsoup 获取特定html源码(无需登录页面) import refrom bs4 import BeautifulSoupimport urllib2 url = 'http:// ...

  7. ajax请求回数组数据,Vue页面数组没同步问题

    记录bug 为什么 ajax 获取到了 vm.$data.list 页面上却没有显示出来的? 代码 //页面 <tr v-for="item in list">{{ * ...

  8. BZOJ 4519 不同的最小割 最小割树

    题面: 把每两个点当成源汇,求N*(N-1)个最小割中不同的有多少个 N<=850 分析: 有这样一个结论:一张无向图不同的最小割最多有n-1个. 那么我们一定可以建出一棵树,使得这棵树中每两个 ...

  9. JavaScript小技巧整理篇(非常全)

    能够为大家提供这些简短而实用的JavaScript技巧来提高大家编程能力,这对于我来说是件很开心的事.每天仅花上不到2分钟的时间中,你将可 以读遍JavaScript这门可怕的语言所呈现给我们的特性: ...

  10. 在rubymine中集成heroku插件

    先安装heroku,参见http://www.cnblogs.com/jecyhw/p/4906990.html Heroku安装之后,就自动安装上git,目录为C:\Program Files (x ...