[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对,使得的值最大. 思路: 分数规划题,可以参考<挑战程序竞赛> ...
随机推荐
- ConcurrentHashMap 并发HashMap原理分析
ConcurrentHashMap和Hashtable主要区别就是围绕着锁的粒度以及如何锁.如图 左边便是Hashtable的实现方式---锁整个hash表:而右边则是Concurrent ...
- mybatis入门截图总结
原生态jdbc存在的问题 ------------------- ----------------------- ------- 环境的搭建 ----------------------------- ...
- JavaScript(DOM编程二)
文档加载完毕之后,在Window.onload方法中创建元素节点,添加到DOM文档中 代码演示: <html> <head lang="en"> <m ...
- BLOB的读写操作
//BLOB写入操作package zxt.xsfw.action.ceshi; import javax.servlet.http.HttpServletRequest; import javax. ...
- 关系数据库标准语言SQL
篇幅过长,恐惧者慎入!!!基础知识,大神请绕道!!! 本节要点: l SQL概述 l 学生-课程关系 l 数据定义 基本表的定义.删除与修改 索引的建立与删除 l 查询 单表查询 连接查询 嵌 ...
- [using_microsoft_infopath_2010]Chapter12 管理监视InfoPath表单服务
本章概要: 1.在SharePoint中心控制台管理InfoPath设置 2.分析监视浏览器表单开考虑潜在性能问题 3.最小化回发数据
- HDU 1575 EASY
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- 多线程的join和interrupt
你可以在一个线程1里添加线程2对象thread的join方法来让线程1处于等待的状态 ,同时也可以调用thread.interrupt()来打断等待状态,此处注意 interrupt应在线程1开启st ...
- Android - 加入Android的OpenCV依赖库(Android Dependencies) 问题
加入Android的OpenCV依赖库(Android Dependencies) 问题 本文地址: http://blog.csdn.net/caroline_wendy 假设想要加入OpenCV的 ...
- Educational Codeforces Round 12 E. Beautiful Subarrays trie求两异或值大于等于k对数
E. Beautiful Subarrays One day, ZS the Coder wrote down an array of integers a with elements a1, ...