题意:有n场考试,给出每场答对的题数a和这场一共有几道题b,求去掉k场考试后,公式.的最大值 解题关键:01分数规划,double类型二分的写法(poj崩溃,未提交) 或者r-l<=1e-3(右边是精度) 为什么v-xw>=0?(v/x>=x?) ans要求的是最大值,我们定义:c(x)可以选择使得单位重量的价值>=x,最大值一定满足此函数,此函数关于x单调递减,可以求得一个最大值.求得的x的最大值即是ans. #include<cstdio> #include<…
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13615   Accepted: 4780 Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumula…
题意 给你n次测试的得分情况b[i]代表第i次测试的总分,a[i]代表实际得分. 你可以取消k次测试,得剩下的测试中的分数为 问分数的最大值为多少. 题解 裸的01规划. 然后ans没有清0坑我半天. #include<iostream> #include<cstring> #include<cmath> #include<cstdio> #include<algorithm> using namespace std; ; double a[N]…
裸题 看分析请戳这里:http://blog.csdn.net/hhaile/article/details/8883652 #include<stdio.h> #include<algorithm> using namespace std; ; ; int n,k; double a[N],b[N],c[N]; int main() { while(~scanf("%d%d",&n,&k)){ if(!n&&!k)break;…
Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8176   Accepted: 2862 Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . Given…
Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 [Description] In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . G…
给出n(n<=1000)个考试的成绩ai和满分bi,要求去掉k个考试成绩,使得剩下的∑ai/∑bi*100最大并输出. 典型的01分数规划 要使∑ai/∑bi最大,不妨设ans=∑ai/∑bi,则∑ai-ans*∑bi=0. 设f[ans]=∑ai-ans*∑bi,我们要求一个ans的最大值,使得存在一组解,满足f[ans]=0,而其他的任意解都有f[ans]<=0(如果f[ans]>0,说明∑ai/∑bi>ans,即还有比ans更优的解),对于∑ai/∑bi,从0~1二分枚举答案…
正解:01分数规划 解题报告: 传送门! 板子题鸭,,, 显然考虑变成$a[i]-mid\cdot b[i]$,显然无脑贪心下得选出最大的$k$个然后判断是否大于0就好(,,,这么弱智真的算贪心嘛$TT$ 然后就做完辣,,, 我真的$jio$得我做的题越来越水了是为什么,,,啊难过,越来越菜了可海星$TT$ #include<algorithm> #include<iomanip> #include<cstdio> using namespace std; #defin…
题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表选取i,否则x[i]=0. 求一个选择方案使得所有选择物品的总收益/总代价的值最大或是最小. 即y=Σ(a[i]*x[i])/Σ(b[i]*x[i])取得最值. 2.这类问题可以用二分解决. 最大化平均值: 设某种选取方案后得到的值为Σa[i]/Σb[i],判断此时二分到的值mid是否符合要求,若Σ…
Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . Given your test scores and a positive integer k, determine how high you can make your cumulative averag…
果然比二分要快将近一倍.63MS.二分94MS. #include <iostream> #include <algorithm> #include <cstdio> #include <ctime> #include <cstdlib> #include <cmath> using namespace std; const int maxn=1005; double a[maxn],b[maxn]; const double eps…
[POJ2976]Dropping Tests(分数规划) 题面 Vjudge 翻译在\(Vjudge\)上有(而且很皮) 题解 简单的\(01\)分数规划 需要我们做的是最大化\(\frac{\sum a[i]}{\sum b[i]}\) 考虑二分答案 将最大化问题转换为判定问题 \(\sum{a[i]}-mid\sum{b[i]}\geq 0\) 因为所有选定的\(i\)是一样的 所以可以将权值化为\(a[i]-mid·b[i]\),这样只需要贪心的选择最大的那部分检查是否大于零就行了 #i…
In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . Given your test scores and a positive integer k, determine how high you can make your cumulative average if you are…
Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11367   Accepted: 3962 Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . Give…
http://poj.org/problem?id=2976 题意: 给出ai和bi,ai和bi是一一配对的,现在可以删除k对,使得的值最大. 思路: 分数规划题,可以参考<挑战程序竞赛>第144页. 枚举答案x,然后去判断是否存在$\frac{\sum a[i]}{\sum b[i]}>=x$,现在把这个式子转换一下,变成$\sum a[i]-x*\sum b[i]>=0$,这样每次贪心选择前面最大的n-k个即可,判断和x的大小关系. #include<iostream&g…
原题: 传送门 题意: 给出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) mem…
题目链接:http://poj.org/problem?id=2976 关于 0/1分数规划 参见 这篇博客 实现代码如下: #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> using namespace std; const int maxn = 1010; const double eps = 1e-4; int n, k; double a[maxn…
传送门:>Here< 题意:给出长度相等的数组a和b,定义他们的和为$\dfrac{a_1+a_2+...+a_n}{b_1+b_2+...+b_n}$.现在可以舍弃k对元素(一对即$a[i]和b[i]$),问最大的和是多少? 解题思路 01分数规划入门题(并没有学过,看到hy大佬在刷因此也去学了下) 问题可以转化为数组中的每个元素选或不选,也就可以认为每一个元素都乘上一个$x[i], \ x[i] ∈ \{0, 1\}$ 因此问题可以转化为$ans = \dfrac{\sum\limits_…
Description 今年有 n 场 ACM-ICPC 竞赛,小明每场都有资格参加.第 i 场竞赛共有 b[i] 道题.小明预测第 i场他能做出 a[i] 道题.为了让自己看着更“大佬”一些,小明想让自己平均做出的题数越大越好,也就是最大化大佬度,大佬度的定义如下: 为了达到这个目的,小明决定放弃 k 场比赛的参赛资格.请求出最大的大佬度. 例如有 3 场小型比赛,题数分别是 5 题.1 题.6 题,小明预测自己分别能做出 5 题.0题.2题.如果每场都参加,那么大佬度是 ,看着不怎么大佬.不…
Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:17069   Accepted: 5925 Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . Given…
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be Given your test scores and a positive integer k, d…
P.S.又是一个抽时间学了2个小时的新东西......讲解在上半部分,题解在下半部分. 先说一下转的原文:http://www.cnblogs.com/perseawe/archive/2012/05/03/01fsgh.html我挑选部分转了过来:01分数规划问题 定义:给定两个数组,a[i]表示选取i的收益,b[i]表示选取i的代价.如果选取i,定义x[i]=1否则x[i]=0.每一个物品只有选或者不选两种方案,求一个选择方案使得R=sigma(a[i]*x[i])/sigma(b[i]*x…
poj2976 题意 给出 a b 数组,一共 n 对数,其中最多可以去掉 k 对,问怎样使剩下比率(原始比率是 $ \frac{\sum_{i=1}^{n} a}{\sum_{i=1}^{n} b}*100 $)最大. 分析 01分数规划 设 \(l=\frac{\sum a}{\sum b}\),我们要求使得 l 最大,构造新函数 \(F()={\sum a}-l*{\sum b}\),设\(D()=a-l*b\),显然 F() 是随 l 增大单调递减的,如果对于某个 l 使得 F() >…
poj2976 题意 给出 a b 数组,一共 n 对数,其中最多可以去掉 k 对,问怎样使剩下比率(原始比率是 $ \frac{\sum_{i=1}^{n} a}{\sum_{i=1}^{n} b}*100 $)最大. 分析 01分数规划 设 \(l=\frac{\sum a}{\sum b}\),我们要求使得 l 最大,构造新函数 \(F()={\sum a}-l*{\sum b}\),设\(D()=a-l*b\),显然 F() 是随 l 增大单调递减的,如果对于某个 l 使得 F() >…
传送门 01分数规划板子题啊. 就是简单变形移项就行了. 显然 ∑i=1na[i]∑i=1nb[i]≤k" role="presentation" style="position: relative;">∑ni=1a[i]∑ni=1b[i]≤k∑i=1na[i]∑i=1nb[i]≤k 于是我们二分k. 只需检验: ∑i=1n(a[i]−b[i]∗k)≤0" role="presentation" style="…
01分数规划 前置技能 二分思想最短路算法一些数学脑细胞? 问题模型1 基本01分数规划问题 给定nn个二元组(valuei,costi)(valuei,costi),valueivaluei是选择此二元组获得的价值(非负),costicosti是选择此二元组付出的代价(非负),设xi(xi∈{0,1})xi(xi∈{0,1})代表第ii个二元组的选与不选,最大(小)化下式 maximize(or minimize)   r=∑valuei⋅xi∑costi⋅ximaximize(or mini…
因为搜索关于CFRound277.5E题的题解时发现了这篇文章,很多地方都有值得借鉴的东西,因此转了过来 原文:http://www.cnblogs.com/perseawe/archive/2012/05/03/01fsgh.html [关键字] 0/1分数规划.最优比率生成树.最优比率环 [背景] 根据楼教主的回忆录,他曾经在某一场比赛中秒掉了一道最优比率生成树问题,导致很多人跟风失败,最终悲剧. 自己总结了一些这种问题的解法,因为水平有限,如果有错误或是麻烦的地方,尽管喷,邮箱或是下方留言…
Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9703   Accepted: 3299 Description Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to…
[题意]给出一个带权无向图,求割集,且割集的平均边权最小. [分析] 先尝试着用更一般的形式重新叙述本问题.设向量w表示边的权值,令向量c=(1, 1, 1, --, 1)表示选边的代价,于是原问题等价为: Minimize   λ = f(x) = sigma(wexe)/sigma(1*xe) = w•x / c•x 其中, x表示一个解向量,xe∈{0, 1} ,即对于每条边都有选与不选两种决策,并且选出的边集组成一个s-t边割集. 联系已有的知识,这是一个0-1分数规划.在胡伯涛<最小割…
[题意]每条路径有一个 cost 和 dist,求图中 sigma(cost) / sigma(dist) 最小的生成树. 标准的最优比率生成树,楼教主当年开场随手1YES然后把别人带错方向的题Orz-- ♦01分数规划 参考Amber-胡伯涛神牛的论文<最小割模型在信息学竞赛中的应用> °定义 分数规划(fractional programming)的一般形式: Minimize  λ = f(x) = a(x) / b(x)   ( x∈S  && ∀x∈S, b(x) &…