题目链接:click here~~

【题目大意】给你n个分数的值,要求最小不选k个,使得最后分数相加结果平均值最大

【解题思路】:最大化平均值:參见:click here~~

代码:

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+10;
const double eps=1e-8;
double y[N],v[N],w[N];
int n,k,m;
bool get(double mid)//能够选择使得单个分数的值不小于mid
{
bool pk;
for(int i=0; i<n; i++) y[i]=v[i]-mid*w[i];
sort(y,y+n); //从大到小排序
double sum=0;
for(int i=0; i<n-k; i++)
sum+=y[n-i-1];//从大往小选择
if(sum>=0) pk=true;
else pk=false;
return pk;
}
int main()
{
//freopen("1.txt","r",stdin);
while(scanf("%d%d",&n,&k)!=EOF)
{
if(n==0&&k==0) break;
for(int i=0; i<n; i++) scanf("%lf",&v[i]);
for(int i=0; i<n; i++) scanf("%lf",&w[i]);
double ll=0,rr=1e10;
while(fabs(ll-rr)>eps){
double mid=(ll+rr)/2;
if(get(mid)) ll=mid;
else rr=mid;
}
printf("%.0f\n",rr*100);
}
return 0;
}

POJ 2976 Dropping tests (最大化平均值)的更多相关文章

  1. poj 2976 Dropping tests (最大化平均值:二分查找)

    #include<iostream> #include<algorithm> #include<stdio.h> #include<math.h> #d ...

  2. 二分算法的应用——最大化平均值 POJ 2976 Dropping tests

    最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...

  3. POJ - 2976 Dropping tests && 0/1 分数规划

    POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} ...

  4. POJ 2976 Dropping tests 【01分数规划+二分】

    题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  5. POJ 2976 Dropping tests【二分 最大化平均值】

    题意:定义最大平均分为 (a1+a2+a3+---+an)/(b1+b2+---+bn),求任意去除k场考试的最大平均成绩 和挑战程序设计上面的最大化平均值的例子一样 判断是否存在x满足条件 (a1+ ...

  6. POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))

    题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...

  7. POJ 2976 Dropping tests(01分数规划入门)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11367   Accepted: 3962 D ...

  8. POJ 2976 Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:17069   Accepted: 5925 De ...

  9. POJ 2976 Dropping tests 01分数规划 模板

    Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 ...

随机推荐

  1. 运行时候报异常could only be replicated to 0 nodes instead of minReplication (=1). There are 2 datanode(s) running and no node(s) are excluded in this operation.

    运行时候报异常could only be replicated to 0 nodes instead of minReplication (=1).  There are 2 datanode(s) ...

  2. poj 3132

    Sum of Different Primes Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3360   Accepted ...

  3. 【构造】Gym - 100781B - Bell Ringing

    根据n-1推n的情况,让n从每一个的最右走到最左,再从下一个最左走到最右,如此往复即可. #include<cstdio> using namespace std; int n,a[500 ...

  4. 【(博弈)dfs序+树状数组】BZOJ2819-Nim

    [题目大意] 普通的Nim游戏为:两个人进行游戏,N堆石子,每回合可以取其中某一堆的任意多个,可以取完,但不可以不取.谁不能取谁输.这个游戏是有必胜策略的.现在对每一堆编号1,2,3,4,...n,在 ...

  5. mysql表相关操作

    表的完整性约束 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性 主要分为: not null  标识该字段不能为空 default   为该字段设置默认值 unsign ...

  6. codevs 1297 硬币

    1297 硬币  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 我们知道即使是同一种面值的硬币, ...

  7. <摘录>GCC 中文手

    GCC 中文手册 作者:徐明 GCC Section: GNU Tools (1) Updated: 2003/12/05 Index Return to Main Contents -------- ...

  8. Node.js中的express框架获取参数

    express获取参数有三种方法: req.query  适合 http://localhost:3000/form?num=8888 req.body   适合http://localhost:30 ...

  9. python2解决中文问题(无论是注释还是代码含有中文)

    interpreter:翻译器; 方式一:在第一行写上#coding=utf-8 方式二:在第一行写上#-*- coding:utf-8 -*-

  10. 万里长征第二步——django个人博客(第二步 ——日志记录器)

    定义日志记录器 可以在setting.py里设置日志记录器 # 自定义日志输出信息 LOGGING = { 'version': 1, 'disable_existing_loggers': True ...