poj2976 Dropping tests(01分数规划 好题)
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分数规划 好题)的更多相关文章
- [poj2976]Dropping tests(01分数规划,转化为二分解决或Dinkelbach算法)
题意:有n场考试,给出每场答对的题数a和这场一共有几道题b,求去掉k场考试后,公式.的最大值 解题关键:01分数规划,double类型二分的写法(poj崩溃,未提交) 或者r-l<=1e-3(右 ...
- POJ2976 Dropping tests —— 01分数规划 二分法
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ2976 Dropping tests(01分数规划)
题意 给你n次测试的得分情况b[i]代表第i次测试的总分,a[i]代表实际得分. 你可以取消k次测试,得剩下的测试中的分数为 问分数的最大值为多少. 题解 裸的01规划. 然后ans没有清0坑我半天. ...
- POJ2976 Dropping tests 01分数规划
裸题 看分析请戳这里:http://blog.csdn.net/hhaile/article/details/8883652 #include<stdio.h> #include<a ...
- Dropping tests(01分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8176 Accepted: 2862 De ...
- POJ 2976 Dropping tests 01分数规划 模板
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6373 Accepted: 2198 ...
- $POJ$2976 $Dropping\ tests$ 01分数规划+贪心
正解:01分数规划 解题报告: 传送门! 板子题鸭,,, 显然考虑变成$a[i]-mid\cdot b[i]$,显然无脑贪心下得选出最大的$k$个然后判断是否大于0就好(,,,这么弱智真的算贪心嘛$T ...
- POJ - 2976 Dropping tests(01分数规划---二分(最大化平均值))
题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...
- POJ 2976 Dropping tests 01分数规划
给出n(n<=1000)个考试的成绩ai和满分bi,要求去掉k个考试成绩,使得剩下的∑ai/∑bi*100最大并输出. 典型的01分数规划 要使∑ai/∑bi最大,不妨设ans=∑ai/∑bi, ...
- 【POJ2976】Dropping tests - 01分数规划
Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...
随机推荐
- PHP7 学习笔记(十七)变量函数 - unset
https://secure.php.net/manual/zh/function.unset.php unset()函数用来清除.销毁变量,不用的变量,可以用unset()将它销毁. 1.unset ...
- [物理学与PDEs]第1章习题15 媒介中电磁场的电磁动量密度向量与电磁动量流密度张量
对媒质中的电磁场, 推导其电磁动量密度向量及电磁动量流密度张量的表达式 (7. 47) 及 (7. 48). 解答: 由 $$\beex \bea \cfrac{\rd}{\rd t}\int_\Om ...
- Groovy 设计模式 -- 组合模式
Composite Pattern http://groovy-lang.org/design-patterns.html#_chain_of_responsibility_pattern 组合模式, ...
- EffectiveC++ 第7章 模板与泛型编程
我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter 7 模版与泛型编程 Templates and Gen ...
- 入门嵌入式选择2440?树莓派?STM32?4412开发板?
如果了解一下当前IT和物联网发展的形势,就会发现Android工程师越来越受欢迎,相比之下单纯的Linux工程师却逊色不少,当然,Android系统的内核也是Linux的,Linux和Android作 ...
- 学习熟悉箭头函数, 类, 模板字面量, let和const声明
箭头函数:https://blog.csdn.net/qq_30100043/article/details/53396517 类:https://blog.csdn.net/pcaxb/articl ...
- php exit die的区别
exit 输出一个消息并且退出当前脚本 void exit([string $status]) void exit(int $status)中止脚本的执行.尽管调用了exit(),Shutdow函数以 ...
- 【easy】112.path sum 113.-----------------
求是否有从根到叶的路径,节点和等于某个值. /** * Definition for a binary tree node. * struct TreeNode { * int val; * Tree ...
- 【原创】大数据基础之Quartz(1)简介、源代码解析
一简介 官网 http://www.quartz-scheduler.org/ What is the Quartz Job Scheduling Library? Quartz is a richl ...
- setInterval动态时间处理