牛客第五场多校 A gpa 分数规划(模板)
链接:https://www.nowcoder.com/acm/contest/143/A
来源:牛客网
At the university where she attended, the final score of her is
Now she can delete at most k courses and she want to know what the highest final score that can get.
输入描述:
The first line has two positive integers n,k The second line has n positive integers s[i] The third line has n positive integers c[i]
输出描述:
Output the highest final score, your answer is correct if and only if the absolute error with the standard answer is no more than 10
-5
输入例子:
3 1
1 2 3
3 2 1
输出例子:
2.33333333333
-->
备注:
1≤ n≤ 10
5
0≤ k < n 1≤ s[i],c[i] ≤ 10
3
题意:给定 n 门课以及它们的学分和绩点,定义总绩点是所有课的加权平均数,给定一个数 k, 你可以删除最多 k 门课,求你的总绩点最大能到多少 1 <=n <=10^5
分析:假设最大总绩点为D,则题中式子可以转化成∑s[i](c[i]-D)=0
观察式子容易看出这是一个分数规划问题,我们可以通过二分D来解答,使左边式子结果最接近0的D即是最大总绩点D
以后类似的分数或者方程式不等式求解问题都可以用这种方式求解
01分数参考博客:https://blog.csdn.net/hhaile/article/details/8883652
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
ll s[maxn], c[maxn], n, k;
double le, ri, t[maxn];
bool check( double x ) {
for( ll i = 1; i <= n; i ++ ) {
t[i] = s[i]*(c[i]-x);
}
sort( t+1, t+n+1 );
double tmp = 0.0;
for( ll i = k+1; i <= n; i ++ ) {
tmp += t[i];
}
return tmp>0;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> k;
for( ll i = 1; i <= n; i ++ ) {
cin >> s[i];
}
for( ll i = 1; i <= n; i ++ ) {
cin >> c[i];
ri = max( ri, (double)c[i] );
}
double mid;
while( ri-le > 1e-6 ) {
mid = (le+ri)/2;
//debug(mid);
if( check(mid) ) {
le = mid;
} else {
ri = mid;
}
}
printf("%.10lf\n",mid);
return 0;
}
牛客第五场多校 A gpa 分数规划(模板)的更多相关文章
- 牛客第五场多校 J plan 思维
链接:https://www.nowcoder.com/acm/contest/143/J来源:牛客网 There are n students going to travel. And hotel ...
- 2019牛客第八场多校 E_Explorer 可撤销并查集(栈)+线段树
目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)E_Explorer) 题意: 链接 题目类似:CF366D,Gym101652T 本题给你\(n(100000)\)个点\(m(1000 ...
- 牛客第三场多校 E Sort String
链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequen ...
- 牛客第三场多校 H Diff-prime Pairs
链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...
- 牛客第五场 G max 思维
链接:https://www.nowcoder.com/acm/contest/143/G来源:牛客网 Give two positive integer c, n. You need to find ...
- PACM Team(牛客第三场多校赛+dp+卡内存+打印路径)
题目链接(貌似未报名的不能进去):https://www.nowcoder.com/acm/contest/141/A 题目: 题意:背包题意,并打印路径. 思路:正常背包思路,不过五维的dp很容易爆 ...
- 2019牛客第八场多校 D_Distance 三维BIT或定期重建套路
目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)D_Distance) 题意: 在三维空间\((n\times m\times h\le 100000)\)内,有\(q(q\le 100 ...
- 牛客网暑期ACM多校训练营(第五场):F - take
链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...
- 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...
随机推荐
- 经典SQL(sqlServer)
一.基础 .说明:创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..) .分组: ...
- 插入Oracle数据库后返回当前主键id
最近做一个spring版本3.0.4的老项目功能,应用场景要用到插入oracle表后返回主键ID拿来和其他表关联. 用oralce的可以一直用这种处理方式,高兼容低,搜索网上的资料都不能和这个Spri ...
- 夯实Java基础(十一)——内部类
1.内部类的概念 内部类顾名思义:将一个类定义在另一个类里面或者一个方法里面,这样的类称为内部类.对于很多Java初学者来说,内部类学起来真的是一头雾水,根本理解不清楚是个什么东西,包括我自己(我太菜 ...
- mysql新建用户及授权
添加用户 CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; -- username : 自定义用户名 -- localhost ...
- c++/c关于函数指针
顺便提一句:指针也是一种变量类型 和 int double 这些类型是一个级别 不同的是它的值是地址 #include "stdafx.h"#include<stdlib.h ...
- AWS Aurora数据库 Multi-Master 小测
AWS Aurora Mysql终于推出了Multi-Master,直面硬刚Oracle RAC.在多一份数据库产品选择的小兴奋之余,我们也看看新推出的Multi-Master的特点(包括优缺点). ...
- 6、高级的数组的复制(test4.java)
这里指的高级,并不是过么高大上,而是说我们可以调用系统函数,直接对数组进行复制,并且这个函数的强大并不止局限于,对数组的复制,而且可以对数组进行截取,在指定位置插入或删除某个元素. 本篇只介绍数组的复 ...
- Python 环境管理
Python 版本管理器:pyenv zsh 配置 # 安装 curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv ...
- 通过Blazor使用C#开发SPA单页面应用程序(2)
今天我们尝试创建一个默认的Blazor应用. 1.安装 .Net Core 3.0需要Visual Studio 2019 的支持. 安装.Net Core 3.0 预览版 SDK版本,注意预览版对应 ...
- 带图标和多行显示的ListBox
源码https://www.codeproject.com/Articles/15464/Extending-the-ListBox-to-show-more-complex-items 定义控件 u ...