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 ...
随机推荐
- 2019-3-27-win10-uwp-动画移动滑动条的滑块
title author date CreateTime categories win10 uwp 动画移动滑动条的滑块 lindexi 2019-03-27 10:51:32 +0800 2019- ...
- LeetcCode102 Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- selenium实现网页截全屏
from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument('--headless' ...
- javascript、jquery、AJAX总结 标签: javascriptjqueryajax 2016-01-23 10:25 2415人阅读
其实在学习之前,就已经用上了js,jquery和ajax,不过当时不清楚这些的区别,就全都当成js来看,然后别人一说jquery,ajax都觉得好像很高级,等到自己学习的时候,倒是对这些更清楚了一点, ...
- Python中json和eval的区别
>>> import json >>> s = '{"one":1,"two":2}' >>> json. ...
- Android中使用Apache common ftp进行下载文件
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/birdsaction/article/details/36379201 在Android使用ftp下 ...
- @noi.ac - 507@ 二分图最大权匹配
目录 @description@ @solution@ @accepted code@ @details@ @description@ 有一天你学了一个能解决二分图最大权匹配的算法,你决定将这个算法应 ...
- LRJ-Example-06-13-Uva1103
pic[][]数组存储每个点的值,0或1,输入时在原图的周围加了一圈0. color[][]数组存储每个点的color值,从1开始,dfs(row, col, c) 负责对每个点着色,连通在一起的连通 ...
- 关于心跳ajax请求pending状态(被挂起),stalled时间过长的问题。涉及tcp连接异常。
环境:景安快云服务器(听说很垃圾,但是公司买的,我也刚来),CentOS-6.8-x86_64,Apache,MySQL5.1,PHP5.3. 问题:现公司有一个php系统,需要重复向后台发送ajax ...
- JavaScript 鼠标事件
鼠标事件是Web开发中最常用的一类事件. DOM3级事件中定义了9个鼠标事件,分别如下: click.dbclick.mousedown.mouseenter.mouseleave.mousemove ...