【POJ - 2010】Moo University - Financial Aid(优先队列)
Moo University - Financial Aid
Descriptions
奶牛大学:奶大招生,从C头奶牛中招收N(N为奇数)头。它们分别得分score_i,需要资助学费aid_i。希望新生所需资助不超过F,同时得分中位数最高。求此中位数。
Input
*第2..C + 1行:每行两个以空格分隔的整数。首先是小牛的CSAT分数; 第二个整数是小牛所需的经济援助金额
Output
Sample Input
- 3 5 70
- 30 25
- 50 21
- 20 20
- 5 18
- 35 30
Sample Output
- 35
Hint
- #include <iostream>
- #include <cstdio>
- #include <fstream>
- #include <algorithm>
- #include <cmath>
- #include <deque>
- #include <vector>
- #include <queue>
- #include <string>
- #include <cstring>
- #include <map>
- #include <stack>
- #include <set>
- #include <sstream>
- #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
- #define Mod 1000000007
- #define eps 1e-6
- #define ll long long
- #define INF 0x3f3f3f3f
- #define MEM(x,y) memset(x,y,sizeof(x))
- #define Maxn 100005
- #define P pair<int,int>
- using namespace std;
- P a[Maxn];
- int N,C,F;
- // 牛i作为中位数时,lower[i]表示分数低于它的牛的学费总和
- int lower[Maxn],upper[Maxn];
- int main()
- {
- cin>>N>>C>>F;
- int half=N/;
- for(int i=; i<C; i++)
- cin>>a[i].first>>a[i].second; //分数 学费
- sort(a,a+C);
- {
- //求出lower[i]
- int total=;
- priority_queue<int>q;
- for(int i=; i<C; i++)
- {
- lower[i]=q.size()==half?total:INF;
- q.push(a[i].second);
- total+=a[i].second;
- if(q.size()>half)
- {
- //去掉一个学费最高的
- total-=q.top();
- q.pop();
- }
- }
- }
- {
- //求出upper[i]
- int total=;
- priority_queue<int>q;
- for(int i=C-; i>=; i--)
- {
- upper[i]=q.size()==half?total:INF;
- q.push(a[i].second);
- total+=a[i].second;
- if(q.size()>half)
- {
- //去掉一个学费最高的
- total-=q.top();
- q.pop();
- }
- }
- }
- int ans=-1;
- for(int i=C-; i>=; i--)
- if(a[i].second+lower[i]+upper[i]<=F)
- {
- ans=a[i].first;
- break;
- }
- cout<<ans<<endl;
- return ;
- }
【POJ - 2010】Moo University - Financial Aid(优先队列)的更多相关文章
- POJ 2010 Moo University - Financial Aid( 优先队列+二分查找)
POJ 2010 Moo University - Financial Aid 题目大意,从C头申请读书的牛中选出N头,这N头牛的需要的额外学费之和不能超过F,并且要使得这N头牛的中位数最大.若不存在 ...
- poj -2010 Moo University - Financial Aid (优先队列)
http://poj.org/problem?id=2010 "Moo U"大学有一种非常严格的入学考试(CSAT) ,每头小牛都会有一个得分.然而,"Moo U&quo ...
- POJ 2010 Moo University - Financial Aid 优先队列
题意:给你c头牛,并给出每头牛的分数和花费,要求你找出其中n(n为奇数)头牛,并使这n头牛的分数的中位数尽可能大,同时这n头牛的总花费不能超过f,否则输出-1. 思路:首先对n头牛按分数进行排序,然后 ...
- poj 2010 Moo University - Financial Aid
Moo Univ ...
- poj 2010 Moo University - Financial Aid 最大化中位数 二分搜索 以后需要慢慢体会
Moo University - Financial Aid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6599 A ...
- poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)
Description Bessie noted that although humans have many universities they can attend, cows have none ...
- POJ 2010 - Moo University - Financial Aid 初探数据结构 二叉堆
考虑到数据结构短板严重,从计算几何换换口味= = 二叉堆 简介 堆总保持每个节点小于(大于)父亲节点.这样的堆被称作大根堆(小根堆). 顾名思义,大根堆的数根是堆内的最大元素. 堆的意义在于能快速O( ...
- POJ 2010 Moo University - Financial Aid (优先队列)
题意:从C头奶牛中招收N(奇数)头.它们分别得分score_i,需要资助学费aid_i.希望新生所需资助不超过F,同时得分中位数最高.求此中位数. 思路: 先将奶牛排序,考虑每个奶牛作为中位数时,比它 ...
- poj 2010 Moo University - Financial Aid (贪心+线段树)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 骗一下访问量.... 题意大概是:从c个中选出n个 ...
- POJ 2010 Moo University - Financial Aid treap
按第一关键字排序后枚举中位数,就变成了判断“左边前K小的和 + 这个中位数 + 右边前K小的和 <= F",其中维护前K小和可以用treap做到. #include <cstdi ...
随机推荐
- 报警提示 System.NullReferenceException:“未将对象引用设置到对象的实例。
System.NullReferenceException:“未将对象引用设置到对象的实例.是就因为Session在记录到服务器时,没有添加 IRequiresSessionState 所以运行时回 ...
- learning scala stripMargin
(1)Scala中创建多行字符串使用Scala的Multiline String. 在Scala中,利用三个双引号包围多行字符串就可以实现. 代码实例如: val foo = "" ...
- 运行级别 runlevel
linux默认有7个等级,从0到6 0 关机 1 单用户模式,系统出现问题是可使用该模式进入系统.例如完了root密码,就可以使用1进入系统修改root密码 2 多用户模式,没有网络连接 3 完全多用 ...
- 关于 js 函数参数的this
先看一道面试题: var number = 10; function fn() { console.log(this.number); } var obj = { number: 2, show: f ...
- 区间连续长度的线段树——洛谷P2894 [USACO08FEB]酒店Hotel
https://www.luogu.org/problem/P2894 #include<cstdio> #include<iostream> using namespace ...
- 1069 The Black Hole of Numbers(20 分)
For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...
- lightgbm用于排序
一. LTR(learning to rank)经常用于搜索排序中,开源工具中比较有名的是微软的ranklib,但是这个好像是单机版的,也有好长时间没有更新了.所以打算想利用lightgbm进行排序, ...
- hadoop3.1.1:找不到或无法加载主类 org.apache.hadoop.mapreduce.v2.app.MRAppMaster
yarn执行MapReduce任务时,找不到主类导致的 解决: 1.在命令行输入:hadoop classpath [hadoop@localhost ~]$ hadoop classpath /da ...
- gitlab怎么用
0101在个人资料里面去设置去找密钥.... 0102 点击生成密钥 0103 在文件夹的命令行输入 ssh-keygen -t rsa -C "your.email@example.com ...
- 【2018.07.27】(字符串/找相同)学习KMP算法小记
虽然说原理很好理解,但是代码理解了花费我一个下午的时间,脑阔痛 该注释的地方都标记了,希望以后看到这些代码我还能好好理解吧 学习的链接地址:https://www.cnblogs.com/teble/ ...