poj 2976 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
#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 二分搜索+精度处理的更多相关文章
- 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 ...
- 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 ...
- POJ 2976 Dropping tests 【01分数规划+二分】
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2976 Dropping tests(01分数规划入门)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11367 Accepted: 3962 D ...
- 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 2976 Dropping tests (0/1分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4654 Accepted: 1587 De ...
- Poj 2976 Dropping tests(01分数规划 牛顿迭代)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n t ...
随机推荐
- 单页面应用 之 项目中集成插件vue-router
\es6\my-complex-project>npm install vue-router -S (S 表示这个包下载到,当前的项目中) 导入写好的 router 这里尽量使用 @ ...
- 04: redis集群
1.1 主从同步 1.CPA原理 1. CPA原理是分布式存储理论的基石: C(一致性): A(可用性): P(分区容忍性); 2. 当主从网络无法连通时,修改操作无法同步到节点,所以“一致性” ...
- Python验证码登录(Tesseract安装配置)
1.安装py库:pytesseract,PIL pip install pytesseract pip install PILLOW 如果安装时,出现权限不足: pip install --user ...
- 14、PCA分析
做芯片PCA主成分分析可以选择使用affycoretools包的plotPCA方法,以样品"GSM363445_LNTT.CEL"."GSM362948_LTT.CEL& ...
- spring boot zuul集成kubernetes等第三方登录
介绍一下,在单点登录平台集成kubernetes登录,集成其它系统的登录原理是一样的,如grafana, nacos, jenkins等. POM引用: <dependency> < ...
- CentOS下安装DockerCE
title: CentOS下安装DockerCE comments: false date: 2019-09-04 09:47:58 description: 在CentOS下安装社区版Docker ...
- sqlserver2016 management tool v18
安装完sql server 2016 sp1版本后再安装管理工具v18版本,启动管理工具,启动不起来,自动退出了,没有任何反应. 解决该问题方案: 找到Microsoft.VisualStudio.S ...
- 多线程编程-- part5.1 互斥锁之非公平锁-获取与释放
非公平锁之获取锁 非公平锁和公平锁在获取锁的方法上,流程是一样的:它们的区别主要表现在“尝试获取锁的机制不同”.简单点说,“公平锁”在每次尝试获取锁时,都是采用公平策略(根据等待队列依次排序等待):而 ...
- webpack4 打包
1. 基本安装及命令 npm config set registry https://registry.npm.taobao.org // 淘宝镜像npm install webpack-c ...
- 给Tomcat打开远程debug端口
>cd apache-tomcat-8.5.24 >cd conf >vim catalina.sh 在文件开始处添加: CATALINA_OPTS="-server -X ...