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 ...
随机推荐
- [再寄小读者之数学篇](2014-04-08 from 1297503521@qq.com $\sin x-x\cos x=0$ 的根的估计)
(2014-04-08 from 1297503521@qq.com) 设方程 $\sin x-x\cos x=0$ 在 $(0,+\infty)$ 中的第 $n$ 个解为 $x_n$. 证明: $$ ...
- LINQ to SQL 调用 SQL Server 的系统函数
Ø 简介 在 C# 中比较常用的 ORM(Object Relational Mapping)框架就是 EF 了,EF 经常结合 LINQ to SQL 来操作数据库.本文主要讨论如何在 LINQ ...
- Executors的四种线程池
Executors.newCachedThreadPool(); Executors.newFixedThreadPool(2); Executors.newScheduledThreadPool(2 ...
- 五子棋.html
二维数组的定义 , canvas对象的使用 二维数组:以下用new,其实简化 [] 即可, var tArray = new Array(); //先声明一维 for(var k=0;k<i;k ...
- 连接远程MySQL数据库项目启动时,不报错但是卡住不继续启动的,
连接远程MySQL数据库项目启动时,不报错但是卡住不继续启动的, 2018-03-12 17:08:52.532DEBUG[localhost-startStop-1]o.s.beans.factor ...
- Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC
解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF ...
- 手写代码 - java.util.Arrays 相关
1-拷贝一个范围内的数组 Arrays.copyOfRange( array, startIndex, endIndex); include startIndex... exclude endInde ...
- Sql Server 字符串操作总结
SQL Server 支持两种字符数据类型---常规和Unicode:常规类型包括char 和varchar:unicode包括nchar 和nvarchar.常规的每个字符占用一个字节存储,而uni ...
- Windows caffe 跑mnist实例
一. 装完caffe当然要来跑跑自带的demo,在examples文件夹下. 先来试试用于手写数字识别的mnist,在 examples/mnist/ 下有需要的代码文件,但是没有图像库. mn ...
- 记账本-NABCD分析
N(Need)需求 这个软件主要解决了大学生管理自己财务状况的问题,随着手机支付的日趋流行大家对财务的概念就变成了银行卡账户余额的一串数字,在不知不觉中,这串数字就一变小,也就出现了月光族.由此看来, ...