POJ - 2976 Dropping tests && 0/1 分数规划
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
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<climits>
#define LL long long
using namespace std;
double RD(){
double out = 0,flag = 1;char c = getchar();
while(c < '0' || c >'9'){if(c == '-')flag = -1;c = getchar();}
while(c >= '0' && c <= '9'){out = out * 10 + c - '0';c = getchar();}
return flag * out;
}
const int maxn = 2019;
int num, K;
double a[maxn], b[maxn],c[maxn];
bool check(double k){
for(int i = 1;i <= num;i++){
c[i] = a[i] - b[i] * k;
}
sort(c + 1, c + 1 + num);
double temp = 0;
for(int i = num;i > K;i--)temp += c[i];
if(temp > 0)return 1;
return 0;
}
double search(double l, double r){
double ans;
while(r - l > 0.000000001){
double mid = (l + r) / 2;
if(check(mid))ans = mid, l = mid;
else r = mid;
}
return ans;
}
int main(){
while(1){
num = RD(), K = RD();
if(!num && !K)return 0;
for(int i = 1;i <= num;i++)a[i] = RD();
for(int i = 1;i <= num;i++)b[i] = RD();
printf("%.0f\n",100 * search(0, 1000000019));
}
}
POJ - 2976 Dropping tests && 0/1 分数规划的更多相关文章
- poj 2976 Dropping tests 0/1分数规划
0/1分数规划问题,用二分解决!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> # ...
- 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分数规划入门)
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:01分数规划【二分】
题目链接:http://poj.org/problem?id=2976 题意: 共有n场考试,每场考试你得的分数为a[i],总分为b[i]. 你可以任意去掉k场考试. 问你最大的 100.0 * ( ...
- POJ 2976 Dropping test(01分数规划模板)
01分数划分详情可阅读:http://www.cnblogs.com/perseawe/archive/2012/05/03/01fsgh.html 题意: 给出n个a和b,让选出n-k个使得最大 二 ...
- 二分算法的应用——最大化平均值 POJ 2976 Dropping tests
最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...
- POJ 2976 Dropping tests【0/1分数规划模板】
传送门:http://poj.org/problem?id=2976 题意:给出组和,去掉对数据,使得的总和除以的总和最大. 思路:0/1分数规划 设,则(其中等于0或1) 开始假设使得上式成立,将从 ...
随机推荐
- 软件工程-东北师大站-第十一次作业(PSP)
PSP 饼状图 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图
- 团队项目M1阶段个人反思
郑培蕾: 作为项目的PM,我前期的工作还是有很大的缺陷的,因为没有在开发之前对项目进行一个合理的评估,所以后来分配任务的时候就很不科学, 而且任务分配的比较粗糙,没有细化到每个人每天应该做什么,这就导 ...
- 2017-2018-2 『Java程序设计』课程 结对编程练习_四则运算
相关测试过程截图(JUnit) JudgeTest:对计算及将整数化为分数的测试 SuffixExpressionTest:中缀转后缀的测试 RationalNumberTest:对RationalN ...
- <<梦断代码>>读后感
<梦断代码>中对软件工程所面临的种种困难与艰难的描述,即便再过5年读也许都不过时.因为正如原作者所说,书中描写的是一队人马并肩扛起代码大石,虽历经磨难仍欲将其推上山顶的故事,而正是这种故事 ...
- Hibernate利用纯sql
String hql = "select * from shop where shop.strid in(select strid from moneythreeshop where mon ...
- 《构建之法》第8,9,10章读后感&sprint1个人总结
第8章 这一章主要介绍需求分析.具体说明了软件需求的类型.利益相关者,获取用户需求分析的常用方法与步骤.竞争性需求分析的框架NABCD,四象限方法以及项目计划和估计的技术.需求分析是决定一个软件的使用 ...
- Delphi判断字符串中是否包含汉字,并返回汉字位置
//1,函数代码{判断字符串是否包含汉字// judgeStr:要判断的字符串//posInt:第一个汉字位置}function TForm2.IsHaveChinese(judgeStr: stri ...
- Word Ladder II Graph
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- Linux下安装 mongodb
1.下载 去官网 https://www.mongodb.com 找到对应版本的mongodb 的下载地址 这样的: https://fastdl.mongodb.org/linux/mongodb ...