【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 ...
随机推荐
- Vue IE11 报错 Failed to generate render function:SyntaxError: 缺少标识符 in
报错截图: 查了篇文章(https://blog.csdn.net/weixin_42018057/article/details/81385121),遇到的情况跟文章里描述的类似,他提供的方法是:需 ...
- 003_创建simulink文件
001_创建simulink文件 1. 打开MATLAB,打开simulink 2. 打开空白模块 3. 保存,并打开模块的选择 4. 在模块里面选择后拖出模块后连线 或在搜索名称后拖出来 或在空白的 ...
- 最短路--Dijkstra
Dijkstra--单源最短路 算法思想 主要记住这句话:每次选择没有被访问过的,并且dis最小的点,加入集合,更新dis 模板 int dis[maxn],vis[maxn]; //距离,标记 vo ...
- 记一次netty的Hadoop和elasticsearch冲突jar包
在一个项目中同时使用hbase和elasticsearch出现netty的jar包冲突的问题 事件: 在同一maven项目中使用hbase的同时又用了es 程序运行后出错 java.lang.NoSu ...
- Ubuntu 14.04 改变文件或者文件夹的拥有者
只有系统管理者(root)才有这样的权限#将文件 file1.txt 的拥有者设为 runoob,群体的使用者 runoobgroupchown runoob:runoobgroup file1.tx ...
- 入门cmake,窥探编译过程
https://www.cnblogs.com/hg-love-dfc/p/10242391.html https://www.cnblogs.com/hg-love-dfc/p/10244328.h ...
- commit 没有提交图片,但是出现了commit的修改
.gitignore里面写上 image/cache/ 就好了
- js 根据滚动条加载数据
很久没记笔记了,最近搞起web开发了 <html> <head> <script src="http://code.jquery.com/jquery-1.7. ...
- 深入理解JVM虚拟机1:JVM内存的结构与永久代的消失
所有的Java开发人员可能会遇到这样的困惑?我该为堆内存设置多大空间呢?OutOfMemoryError的异常到底涉及到运行时数据的哪块区域?该怎么解决呢?其实如果你经常解决服务器性能问题,那么这些问 ...
- Git .gitignore中已添加文件路径,但仍未被忽略
当文件之前已经被提交到仓库后,后面即使将文件路径添加到 .gitignore ,使用 git status 命令,依然会看到文件被修改. $ git status 位于分支 master 您的分支与上 ...