牛客第五场多校 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,之 ...
随机推荐
- Linux内核OOM killer机制
程序运行了一段时间,有个进程挂掉了,正常情况下进程不会主动挂掉,简单分析后认为可能是运行时某段时间内存占用过大,系统内存不足导致触发了Linux操作系统OOM killer机制,将运行中的进程杀掉了. ...
- CountDownLatch实现多线程并发请求
package com.test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Dat ...
- oracle的JDBC连接
package com.xian.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Pr ...
- memcached.c 源码分析
上文分析了memcached的autoconf过程以及configure, make过程,可以看到,memcached可执行文件是由memcached-memcached.o以及其他文件连接后编译出来 ...
- javascript+jQuery补充
一.jQuery事件绑定 <div class='c1'> <div> <div class='title'>菜单一</div> <div cla ...
- .NET Core 3.0深入源码理解HttpClientFactory之实战
写在前面 前面两篇文章透过源码角度,理解了HttpClientFactory的内部实现,当我们在项目中使用时,总会涉及以下几个问题: HttpClient超时处理以及重试机制 HttpClient ...
- java课堂 动手动脑3
(1) 该函数没有赋初值再就是如果类提供一个自定义的构造方法,将导致系统不在提供默认的构造方法. (2) public class test { public static void main(Str ...
- Docker笔记(七):常用服务安装——Nginx、MySql、Redis
开发中经常需要安装一些常用的服务软件,如Nginx.MySql.Redis等,如果按照普通的安装方法,一般都相对比较繁琐 —— 要经过下载软件或源码包,编译安装,配置,启动等步骤,使用 Docker ...
- Oracle 存储过程批量插入数据
oracle 存储过程批量插入大量数据 declare numCount number; userName varchar2(512); email varchar2(512); markCommen ...
- html的一些基本属性介绍
一.html的属性类型: 1.常见标签属性: a.<h1>:align对其方式 例如:<h1 align="right"> hhhhh</ ...