POJ 2976 Dropping tests [二分]
1.题意:同poj3111,给出一组N个有价值a,重量b的物品,问去除K个之后,剩下的物品的平均值最大能取到多少?
2.分析:二分平均值,注意是去除K个,也就是选取N-K个
3.代码:
# include <iostream>
# include <cstdio>
# include <cmath>
# include <algorithm>
using namespace std;
const int MAXN=;
const double eps=1e-;
int N,K;
int sgn(double x)
{
if(fabs(x)<eps) return ;
if(x<) return -;
else return ;
}
struct Test
{
double a,b;
Test(){}
Test(double aa,double bb)
{
a=aa;
b=bb;
}
}T[MAXN];
void Init()
{
for(int i=;i<N;i++)
scanf("%lf",&T[i].a);
for(int i=;i<N;i++)
scanf("%lf",&T[i].b);
}
void Solve()
{
double temp[MAXN];
double sum;
double l=0.0;
double r=2.0;
while(sgn(r-l)!=)
{
double mid=l+(r-l)/2.0;
for(int i=;i<N;i++)
temp[i]=mid*T[i].b-T[i].a;
sort(temp,temp+N);
sum=;
for(int i=;i<N-K;i++)
sum+=-temp[i];
//printf("%lf %lf\n",mid,sum);
if(sgn(sum)<) r=mid;
else l=mid;
}
printf("%0.f\n",100.0*l);
}
int main()
{
while(scanf("%d%d",&N,&K)!=EOF)
{
if(N==&&K==) break;
Init();
Solve();
}
return ;
}
POJ 2976 Dropping tests [二分]的更多相关文章
- POJ 2976 Dropping tests (二分+贪心)
题意:给定 n 个分数,然后让你去年 m 个分数,使得把剩下的所有的分子和分母都相加的分数最大. 析:这个题并不是分子越大最后结果就越大,也不是整个分数越大,最后结果就越大的,我们可以反过来理解,要去 ...
- 二分算法的应用——最大化平均值 POJ 2976 Dropping tests
最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...
- 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 【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: 6373 Accepted: 2198 ...
- 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: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 ...
随机推荐
- nginx 做反向代理
1.Nginx的常用配置大家可以去搜一下,有很多优秀的博客,我这篇文章要实现的需求是: a.根据访问的域名不同,跳转到不同的项目(html首页,80端口) b.拦截访问中所有带有api的请求,转发到后 ...
- thinkphp5.0 路由规则配置
开启路由‘url_route_on’ => true 首页路由'/' =>'home/index/index' 其它路由(1)'route' => 'home/index/route ...
- 2019-9-18-WPF-笔刷绑定不上可能的原因
title author date CreateTime categories WPF 笔刷绑定不上可能的原因 lindexi 2019-09-18 09:46:14 +0800 2019-9-18 ...
- HDU-1114_Piggy-Bank
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- python 自动识别黄图
from watchdog.observers import Observerfrom watchdog.events import *import timeimport sysimport osim ...
- oracle函数 LPAD(c1,n[,c2])
[功能]在字符串c1的左边用字符串c2填充,直到长度为n时为止 [参数]C1 字符串 n 追加后字符总长度 c2 追加字符串,默认为空格 [返回]字符型 [说明]如果c1长度大于n,则返回c1左边n个 ...
- @noi.ac - 493@ trade
目录 @description@ @solution@ @part - 1@ @part - 2@ @part - 3@ @part - 4@ @accepted code@ @details@ @d ...
- PHP_APC扩展dll上传大文件及进度条实例
1.弄好了APC之后,就是使用它了,下面是个例子,是一个进度条上传的例子,作为笔记记录下来 在这个例子之前,我们需要做如下的设置,如果我们需要上传的是大文件的话,请在您的php.ini文件中做如下的设 ...
- H3C 网络层
- 【原生JS】评论编辑器 文本操作
效果图: HTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...