Dropping tests(01分数规划)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8176 | Accepted: 2862 |
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
题解:给你n个数,让求删除k个数后
的最大值;01分数规划;
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=;
struct Node{
int a,b;
};
Node dt[MAXN];
double d[MAXN];
int n,k;
bool fsgh(double R){
double sum=;
for(int i=;i<n;i++)d[i]=dt[i].a-R*dt[i].b;
sort(d,d+n);
for(int i=n-;i>=n-k;i--)sum+=d[i];
return sum>?true:false;
}
double erfen(double l,double r){
double mid;
while(r-l>1e-){
mid=(l+r)/;
if(fsgh(mid))l=mid;
else r=mid;
}
return mid;
}
int main(){
while(scanf("%d%d",&n,&k),n|k){
double mx=;
k=n-k;
for(int i=;i<n;i++)scanf("%d",&dt[i].a);
for(int i=;i<n;i++)scanf("%d",&dt[i].b),mx=max(1.0*dt[i].a/dt[i].b,mx);
printf("%.0f\n",erfen(,mx)*);
}
return ;
}
Dropping tests(01分数规划)的更多相关文章
- POJ 2976 Dropping tests 01分数规划 模板
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6373 Accepted: 2198 ...
- POJ 2976 Dropping tests 01分数规划
给出n(n<=1000)个考试的成绩ai和满分bi,要求去掉k个考试成绩,使得剩下的∑ai/∑bi*100最大并输出. 典型的01分数规划 要使∑ai/∑bi最大,不妨设ans=∑ai/∑bi, ...
- [poj2976]Dropping tests(01分数规划,转化为二分解决或Dinkelbach算法)
题意:有n场考试,给出每场答对的题数a和这场一共有几道题b,求去掉k场考试后,公式.的最大值 解题关键:01分数规划,double类型二分的写法(poj崩溃,未提交) 或者r-l<=1e-3(右 ...
- $POJ$2976 $Dropping\ tests$ 01分数规划+贪心
正解:01分数规划 解题报告: 传送门! 板子题鸭,,, 显然考虑变成$a[i]-mid\cdot b[i]$,显然无脑贪心下得选出最大的$k$个然后判断是否大于0就好(,,,这么弱智真的算贪心嘛$T ...
- POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))
题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...
- POJ2976 Dropping tests —— 01分数规划 二分法
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ2976 Dropping tests(01分数规划)
题意 给你n次测试的得分情况b[i]代表第i次测试的总分,a[i]代表实际得分. 你可以取消k次测试,得剩下的测试中的分数为 问分数的最大值为多少. 题解 裸的01规划. 然后ans没有清0坑我半天. ...
- 【POJ2976】Dropping tests - 01分数规划
Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...
- POJ2976 Dropping tests 01分数规划
裸题 看分析请戳这里:http://blog.csdn.net/hhaile/article/details/8883652 #include<stdio.h> #include<a ...
随机推荐
- Mybatis设置自增主键
useGeneratedKeys="true" keyProperty="id" 方法1: <insert id="insert" p ...
- VC++学习之网络编程中的套接字
VC++学习之网络编程中的套接字 套接字,简单的说就是通信双方的一种约定,用套接字中的相关函数来完成通信过程.应用层通过传输层进行数据通信时,TCP和UDP会遇到同时为多个应用程序进程提供并发服务的问 ...
- TinyFox 部署在CentOS7 中测试使用
一:TinyFox介绍 TinyFox 是一款支持OWIN标准的WEB应用的高性能的HTTP服务器,是Jexus Web Server的"姊妹篇".TinyFox本身的功能是htm ...
- java.el.PropertyNotFoundException解决方法
今天在开发中遇到了java.el.PropertyNotFoundException异常,检查JSP页面.Action.Bean.都没有发现错误 在网上搜了一下可能是我的bean不是一个标准的bean ...
- 记录.net 中的常见术语
--Entity Framework和NHibernate --EF和NH都是一种ORM技术.就是对象关系模型映射. --NHibernate和Entity Framework 4.0优劣势争论 -- ...
- protel99与win7兼容问题的解决方案
一些用户大概都已经把自己的 PC 从 winXP 换到了 win7,在 win7 给我们带来的视觉上的冲击和功能上的更换.也不时的带来了各方面的软件兼容问题 ,而一般上的兼容都可以在 win7 的自动 ...
- HDU 2167 Pebbles
题目大意:有个N*N( 3<=N<=15 )方阵, 可从中若干个数, 使其总和最大.取数要求, 当某一个数被选, 其周围8个数都不能选. 题解:记s数组为合法状态,即没有相邻的数字同时被选 ...
- 01-复杂度2. Maximum Subsequence Sum (25)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...
- hdoj 2546 饭卡(0-1背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路分析:该问题为0-1背包问题的变形题:问题求余额最少,设开始的余额为V,则求得用V-5可以买 ...
- Please ensure that adb is correctly located at '...adb.exe' and can be executed.
Android Launch! The connection to adb is down, and a severe error has occured. You must restart adb ...