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 ...
随机推荐
- oracle中常用的时间格式转换
1:取得当前日期是本月的第几周 select to_char(sysdate,'YYYYMMDD W HH24:MI:SS') from dual; TO_CHAR(SYSDATE,'YY') se ...
- python ASCII编码集
- 阿里云oss上传图片报错,The OSS Access Key Id you provided does not exist in our records.解决方法
vue项目 1.安装OSS的Node SDK npm install ali-oss --save 2.参考官方提示https://help.aliyun.com/document_detail/11 ...
- python 类与类之间的关系. 特殊成员
一.类与类之间的关系 1.依赖关系 在方法的参数位置把另一个类的对象作为参数进行传递 class Person: def play(self, tools): # 通过参数的传递把另一个类的对象传递进 ...
- SDUT-2120_数据结构实验之链表五:单链表的拆分
数据结构实验之链表五:单链表的拆分 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入N个整数顺序建立一个单链表,将该 ...
- css属性overflow:hidden在IE6、7下失效解决方案
当父元素的直接子元素或者下级子元素的样式拥有position:relative属性时,父元素的overflow:hidden属性就会失效.我们在IE 6 7内发现子元素会超出父元素设定的高度,即使父元 ...
- @bzoj - 5219@ [Lydsy2017省队十连测]最长路径
目录 @description@ @solution@ @accepted code@ @details@ @description@ 在Byteland一共有n个城市,编号依次为1到n,形成一个n个 ...
- mysql数据库之windows版本
安装 第一步:打开网址,http://www.mysql.com.点击downloads之后跳转到http://www.mysql.com/downloads/选择Community选项 第二步:按 ...
- laravel5.6 发送邮件附带邮件时,Unable to open file for reading,报错文件路径问题
https://stackoverflow.com/questions/48568739/unable-to-open-file-for-reading-swift-ioexception-in-la ...
- hdu 5734 Acperience(2016多校第二场)
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...