[poj 2976] Dropping tests (分数规划 二分)
原题:
传送门
题意:
给出n个a和b,让选出n-k个使得(sigma a[i])/(sigma b[i])最大
直接用分数规划。。
code:
//By Menteur_Hxy
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#define M(a,b) memset(a,(b),sizeof(a))
#define F(i,a,b) for(register int i=(a);i<=(b);i++)
#define LL long long
using namespace std;
inline LL rd() {
LL x=0,fla=1; char c=' ';
while(c>'9'|| c<'0') {if(c=='-') fla=-fla; c=getchar();}
while(c<='9' && c>='0') x=x*10+c-'0',c=getchar();
return x*fla;
}
const int N=1010;
const int INF=0x3f3f3f3f;
int n,k;
int a[N],b[N];
double t[N];
double jud(double L) { double sum=0.0;
F(i,1,n) t[i]=a[i]-L*b[i];
sort(t+1,t+1+n);
F(i,k+1,n) sum+=t[i];
return sum;
}
int main() {
while(scanf("%d %d",&n,&k),n||k) {
F(i,1,n) a[i]=rd();
F(i,1,n) b[i]=rd();
double l=0.0,r=1.0;
while(r-l>1e-7) {
double mid=(l+r)/2;
if(jud(mid)>0) l=mid;
else r=mid;
}
printf("%.0f\n",l*100);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
[poj 2976] Dropping tests (分数规划 二分)的更多相关文章
- 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
最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...
- 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分数规划---二分(最大化平均值))
题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表 ...
- 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(01分数规划 牛顿迭代)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n t ...
- POJ 2976 Dropping tests(分数规划)
http://poj.org/problem?id=2976 题意: 给出ai和bi,ai和bi是一一配对的,现在可以删除k对,使得的值最大. 思路: 分数规划题,可以参考<挑战程序竞赛> ...
随机推荐
- Vue JsonView 树形格式化代码插件
组件代码(临时粘出来) <template> <div class="bgView"> <div :class="['json-view' ...
- css 垂直居中方法总结
工作中遇到垂直居中问题,特此总结了一下几种方式与大家分享.本文讨论的垂直居中仅支持IE8+ 1.使用绝对定位垂直居中 HTML <div class="container"& ...
- String类常见的方法
类String public final class String extends Object implements Serializable, comparable<String>, ...
- BA-Siemens-时间表
问题1:弹出了subsystem:atom Identifier 0000000023的错误对话框,此问题目前不知道如何处理,先攒着吧.
- F - Truck History
F - Truck History #include<cstdio> #include<cstring> #include<iostream> #include&l ...
- spring cloud 中Actuator不显示更多信息的处理方式
spring cloud 中Actuator不显示更多信息的处理方式 直接咨询了周大立,他说 management.security.enabled = false 就可以了: 学习了:http:// ...
- Android - 使用JD-GUI反编译Android代码
使用JD-GUI反编译Android代码 本文地址: http://blog.csdn.net/caroline_wendy Android程序出现Bug时,须要依据Bug寻找问题出错的地方; 须要使 ...
- TNS-12555 / TNS-12560 / TNS-00525 Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPR
TNS-12555 / TNS-12560 / TNS-00525 Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPR ...
- BZOJ 1790: [Ahoi2008]Rectangle 矩形藏宝地
BZOJ 1790: [Ahoi2008]Rectangle 矩形藏宝地 题目传送门 [题目大意] 游戏的主办方把这块开阔地当作第一象限,将所有可能埋藏宝藏的地方划成一个个矩形的土地,并把这些矩形土地 ...
- oracle 11gR2 如何修改 private ip
1.1 修改 private ip1.1.1 确保crs集群是打开的可以用olsnodes –s 检查集群的状态./olsnodes -sP570a ActiveP570b Active1.1 ...