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 ...
随机推荐
- hdu4318 最短路变形
和hdu有一题差不多.给的是损失比,1-c%就是保存了多少,找出最大的保存率即可. #include<stdio.h> #include<iostream> #include& ...
- 用GitHub Pages搭了个博客,欢迎来玩~
Welcome to visit my new blog https://luoxiaolei.github.io/ Ps. 后续的blog会优先更新到GitHub Pages上.
- SDUT-2116_数据结构实验之链表一:顺序建立链表
数据结构实验之链表一:顺序建立链表 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入N个整数,按照输入的顺序建立单链 ...
- HDFS命令行界面
- TensorFlow的 卷积层
用 TensorFlow 做卷积 让我们用所学知识在 TensorFlow 里构建真的 CNNs.在下面的练习中,你需要设定卷积核滤波器(filters)的维度,weight,bias.这在很大程度上 ...
- uva 10253 Series-Parallel Networks (整数划分+多重集)
UVa Online Judge 题意是计算给定数量的边通过串联并联两种方式,能组成多少种不同的网络.将它转化为一个树形结构,也就是求有多少不同构的树. 代码如下: #include <cstd ...
- 2019-11-13-如何在国内发布-UWP-应用
title author date CreateTime categories 如何在国内发布 UWP 应用 lindexi 2019-11-13 08:46:44 +0800 2019-02-17 ...
- 2018-8-10-win10-uwp-自定义控件初始化
title author date CreateTime categories win10 uwp 自定义控件初始化 lindexi 2018-08-10 19:16:50 +0800 2018-2- ...
- python单例模式的实现与优化
python单例模式的实现与优化 阅读目录(Content) 单例模式 实现单例模式的几种方式 1.使用模块 2.使用装饰器 3.使用类 4.基于__new__方法实现(推荐使用,方便) 5.基于me ...
- Sphinx中文入门指南
http://www.sphinxsearch.org/sphinx-tutorial 1.简介 1.1.Sphinx是什么 1.2.Sphinx的特性 1.3.Sphinx中文分词 2.安装配置实例 ...