[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对,使得的值最大. 思路: 分数规划题,可以参考<挑战程序竞赛> ...
随机推荐
- Project Euler 27 Quadratic primes( 米勒测试 + 推导性质 )
题意: 欧拉发现了这个著名的二次多项式: f(n) = n2 + n + 41 对于连续的整数n从0到39,这个二次多项式生成了40个素数.然而,当n = 40时402 + 40 + 41 = 40( ...
- EhCache缓存页面、局部页面和对象缓存
页面缓存:SimplePageCachingFilter web.xml <!-- 页面缓存配置,配合ehcache.xml中name为“SimplePageCachingFilter”(默认值 ...
- struts配置
创建struts2的应用,首先应如前面所示要搭建好环境.jar包的导入和web.xml配置这里不在写出来. 如上所示,struts2中是采用<package>元素来管理Action的,包 ...
- POJ 3177--Redundant Paths【无向图添加最少的边成为边双连通图 && tarjan求ebc && 缩点构造缩点树】
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10798 Accepted: 4626 ...
- HorizontalDragLayout-模仿QQclient的Item滑动删除
首先感谢http://blog.csdn.net/lmj623565791/article/details/46858663hongyang的文章.之前看过ViewDragHelper类也读过一些de ...
- Introduction to CMMI培训总结
6月3日到5日,用了3天时间,參加了cmmi-dev的简单介绍课程培训,參加培训真的比上班都要累非常多啊!每天早上9点到下午6点.中午吃饭加歇息总共1小时.晚上还有作业要做,每天睡觉都要到11点 ...
- Cocos2dx之使用UI库结合cocostudio
使用cocostudio的UI编辑器编辑好UI界面,导出UI文件,直接在cocos2dx中使用.通过tag或者name来获取到UI控件 1.编辑ui界面,直接用模板然后拖几个控件过去 2.cocos2 ...
- 【零基础入门学习Python笔记013】元祖:戴上了枷锁的列表
元组:戴上了枷锁的列表 因为和列表是近亲关系.所以元祖和列表在实际使用上是很相似的. 本节主要通过讨论元素和列表究竟有什么不同学习元祖. 元组是不可改变元素的.插入.删除或者排序都不能够.列表能够随意 ...
- redis持久化,rdb,aof
RDB(Redis DataBase) AOF(Append Only File) 周阳语录:能撑过面试经理头一分钟最重要.头一分钟,决定人家还是否想跟你继续聊下去. RDB RDB就是在指定的时间内 ...
- USACO 2.2 Runaround Numbers
Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81 ...