https://vjudge.net/problem/POJ-2976

又是一波c++AC,g++WA的题。。

先推导公式:由题意得 Σa[i]/Σb[i]<=x,二分求最大x。化简为Σ(a[i]-x*b[i])<=0,按a[i]-x*b[i]降序排列,从中取前n-m个和满足该式的话,就说明x多半是偏大了。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
ll a[], b[];
double c[];
ll n, m;
bool cmp(const double a, const double b)
{
return a>b;
}
int C(double x)
{
for(int i = ; i < n; i++){
c[i] = a[i]-x*b[i];
}
sort(c, c+n, cmp);//降序
double ans=;
for(int i = ; i < n-m; i++){
ans += c[i];
}
return ans<=;//
}
int main()
{
while(~scanf("%lld%lld", &n, &m)){
if(!n&&!m) break;
for(int i = ; i < n; i++){
scanf("%lld", &a[i]);
}
for(int i = ; i < n; i++){
scanf("%lld", &b[i]);
}
double lb = , ub = ;
for(int i = ; i < ; i++){
//while(ub-lb>1e-6){
double mid = (ub+lb)/;
if(C(mid)){
ub = mid;
}
else lb = mid;
//cout << mid << endl;
}
printf("%.0lf\n", (ub*));
}
return ;
}

poj2976 Dropping tests(01分数规划 好题)的更多相关文章

  1. [poj2976]Dropping tests(01分数规划,转化为二分解决或Dinkelbach算法)

    题意:有n场考试,给出每场答对的题数a和这场一共有几道题b,求去掉k场考试后,公式.的最大值 解题关键:01分数规划,double类型二分的写法(poj崩溃,未提交) 或者r-l<=1e-3(右 ...

  2. POJ2976 Dropping tests —— 01分数规划 二分法

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

  3. POJ2976 Dropping tests(01分数规划)

    题意 给你n次测试的得分情况b[i]代表第i次测试的总分,a[i]代表实际得分. 你可以取消k次测试,得剩下的测试中的分数为 问分数的最大值为多少. 题解 裸的01规划. 然后ans没有清0坑我半天. ...

  4. POJ2976 Dropping tests 01分数规划

    裸题 看分析请戳这里:http://blog.csdn.net/hhaile/article/details/8883652 #include<stdio.h> #include<a ...

  5. Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8176   Accepted: 2862 De ...

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

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

  7. $POJ$2976 $Dropping\ tests$ 01分数规划+贪心

    正解:01分数规划 解题报告: 传送门! 板子题鸭,,, 显然考虑变成$a[i]-mid\cdot b[i]$,显然无脑贪心下得选出最大的$k$个然后判断是否大于0就好(,,,这么弱智真的算贪心嘛$T ...

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

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

  9. POJ 2976 Dropping tests 01分数规划

    给出n(n<=1000)个考试的成绩ai和满分bi,要求去掉k个考试成绩,使得剩下的∑ai/∑bi*100最大并输出. 典型的01分数规划 要使∑ai/∑bi最大,不妨设ans=∑ai/∑bi, ...

  10. 【POJ2976】Dropping tests - 01分数规划

    Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...

随机推荐

  1. 横向滚动布局 white-space:nowrap

    float + 两层DOM实现 html <div class="container"> <div class="div1 clearfix" ...

  2. django - 总结 - cookie|session

    Cookie是通过HTTP请求和响应头在客户端和服务器端传递的. 在Web开发中,使用session来完成会话跟踪,session底层依赖Cookie技术. --------------------- ...

  3. MyBatis使用注意事项

    目录 1. 使用何种映射器配置 2. 对象生命周期和作用域 SqlSessionFactoryBuilder SqlSessionFactory SqlSession 映射器实例(Mapper Ins ...

  4. A fine property of the non-empty countable dense-in-self set in the real line

    A fine property of the non-empty countable dense-in-self set in the real line   Zujin Zhang School o ...

  5. windows 7中的windows键相关的快捷键

    引用 https://support.microsoft.com/zh-cn/help/976857 Windows 键的位置 如果不清楚 Windows 键的位置,请参照下图: 常用的 Window ...

  6. for 循环 与forEach 里面return 的区别

    for 循环里面 return 可以直接终止 跳出 循环 forEach 是中断本次循环 直接 下一个循环 forEach想要取到值之后 直接跳出循环 可以用 try catch let arr = ...

  7. redis 远程操作命令

    在远程服务上执行命令 如果需要在远程 redis 服务上执行命令,同样我们使用的也是 redis-cli 命令. 语法 $ redis-cli -h host -p port -a password ...

  8. Java基础9-死锁;String;编码

    昨日内容回顾 死锁案例 class DeadLock{ public static void main(String[] args){ Pool pool = new Pool(); Producer ...

  9. OrCAD Capture CIS 16.6 将版本16.6的设计文件另存为版本16.2的设计文件

    操作系统:Windows 10 x64 工具1:OrCAD Capture CIS 16.6-S062 (v16-6-112FF) 启动OrCAD Capture CIS,打开.dsn设计文件,右击该 ...

  10. Jmeter_24个常用函数

    JMeter提供了很多函数,如果能够熟练使用,可以为脚本带来很多方便. JMeter函数是一种特殊值,可用于除测试计划外的任何组件. 函数调用的格式如下所示:${__functionName(var1 ...