POJ2976:Dropping tests——题解】的更多相关文章

---恢复内容开始--- POJ2976 Dropping tests 这个题就是大白P144页的一个变形,二分枚举x,对a[i]-x*b[i]从大到小进行排序,选取前n-k个判断和是否大于等于0,若满足条件,增大下限,否则,减小下限. 这个题因为精度问题wa了n次,后来干脆把a[i]和b[i]改成double就过了,循环终止条件写成while (abs(ub - lb) > 1e-4)比写成for(int i=0;i<100;i++)要好,既能减少时间消耗,又能满足精度. lb和ub初始化时…
题目链接: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…
http://poj.org/problem?id=2976 题目大意:给定n个二元组(a,b),从中取n-k个,使得100*∑a/∑b最大. 01分数规划裸题,设λ是小于等于最优解的,那么λ<=∑a/∑b,先通过移项来得到新的表达法∑a-λ∑b>=0. 就可以二分答案做了. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef double d…
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>…
题意 给你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]…
题目大概说给n个二元组Ai和Bi,要去掉k个,求余下的100*∑Ai/∑Bi的最大值. 假设要的最大的值是ans,令Di=Ai-ans*∑Bi,对Di排序取最大的n-k个,如果∑Ai-ans*∑Bi>0,说明ans还可以更大,反之ans太大了,所以二分枚举一下ans判断即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace st…
裸题 看分析请戳这里: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;…
传送门:>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_…
题意:有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<…
[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…
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…
最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v_i <= ^6 输入:n = 3k = 2{W, V} = {(2,2), (5,3), (2,1)} 输出:0.75 (如果选0号和2号,平均价格是 (2 + 1) / (2 + 2) = 0.75) 题解: 一般先想到的肯定是:把物品按照  单位价值  进行排序,然后从大到小贪心地进行选取.但是这…
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…
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…
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…
[poj P2976] 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 positi…
Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4654   Accepted: 1587 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: 12187   Accepted: 4257 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…
POJ - 2976 Dropping tests 你有 \(n\) 次考试成绩, 定义考试平均成绩为 \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} b_{i}}\] 你可以考虑放弃 \(K\) 次成绩, 求最大平均成绩 * 100 小插曲: 被精度卡成喜羊羊 0/1分数规划\(from\)人生导师 Solution 01分数规划(不是很)裸题, 在每次 \(check\) 时, 选取较大的 \(num - K + 1\) 次即可 Code #…
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17838   Accepted: 6186 Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumula…
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20830   Accepted: 7052 Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumula…
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…
Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8349   Accepted: 2919 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…
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…
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…
Description 今年有 n 场 ACM-ICPC 竞赛,小明每场都有资格参加.第 i 场竞赛共有 b[i] 道题.小明预测第 i场他能做出 a[i] 道题.为了让自己看着更“大佬”一些,小明想让自己平均做出的题数越大越好,也就是最大化大佬度,大佬度的定义如下: 为了达到这个目的,小明决定放弃 k 场比赛的参赛资格.请求出最大的大佬度. 例如有 3 场小型比赛,题数分别是 5 题.1 题.6 题,小明预测自己分别能做出 5 题.0题.2题.如果每场都参加,那么大佬度是 ,看着不怎么大佬.不…
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 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 an…
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 aver…
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…