poj 2010 Moo University - Financial Aid
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 7961 | Accepted: 2321 |
Description
Not wishing to admit dumber-than-average cows, the founders created an incredibly precise admission exam called the Cow Scholastic Aptitude Test (CSAT) that yields scores in the range 1..2,000,000,000.
Moo U is very expensive to attend; not all calves can afford it.In fact, most calves need some sort of financial aid (0 <= aid <=100,000). The government does not provide scholarships to calves,so all the money must come from the university's limited fund (whose total money is F, 0 <= F <= 2,000,000,000).
Worse still, Moo U only has classrooms for an odd number N (1 <= N <= 19,999) of the C (N <= C <= 100,000) calves who have applied.Bessie wants to admit exactly N calves in order to maximize educational opportunity. She still wants the median CSAT score of the admitted calves to be as high as possible.
Recall that the median of a set of integers whose size is odd is the middle value when they are sorted. For example, the median of the set {3, 8, 9, 7, 5} is 7, as there are exactly two values above 7 and exactly two values below it.
Given the score and required financial aid for each calf that applies, the total number of calves to accept, and the total amount of money Bessie has for financial aid, determine the maximum median score Bessie can obtain by carefully admitting an optimal set of calves.
Input
* Lines 2..C+1: Two space-separated integers per line. The first is the calf's CSAT score; the second integer is the required amount of financial aid the calf needs
Output
Sample Input
3 5 70
30 25
50 21
20 20
5 18
35 30
Sample Output
35
Hint
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
const int N_MAX = +;
struct cow {
int score;
int need_money;
bool operator<(const cow&b)const{
return score<b.score ;
}
};
cow cows[N_MAX];
int lower_money[N_MAX];
int upper_money[N_MAX];
int main() {
//cout << 0x3f3f3f3f <<" "<<INT_MAX<<endl;
int N, C, F;
scanf("%d%d%d",&N,&C,&F);
for (int i = ;i < C;i++)
scanf("%d%d",&cows[i].score,&cows[i].need_money);
sort(cows,cows+C);//按成绩从低到高排
priority_queue<int>que;
unsigned int half = N / ,total=;
for (int i = ;i < C;i++) {//对于每一头牛,计算成绩比他低的牛的资金总和的最小值
lower_money[i] = ( que.size() == half ? total : 0x3f3f3f3f);
que.push(cows[i].need_money);
total += cows[i].need_money;
if (que.size() > half) {
total -= que.top();
que.pop();
}
} priority_queue<int>q;
total = ;
for (int i = C - ;i >= ;i--) {
upper_money[i] = (q.size() == half ? total : 0x3f3f3f3f);
q.push(cows[i].need_money);
total += cows[i].need_money;
if (q.size() > half) {
total -= q.top();
q.pop();
}
}
int grade=-;
for (int i = C-;i>=;i--) {
if (upper_money[i] + lower_money[i] + cows[i].need_money <= F) { grade = cows[i].score; break; }
}
if (grade>)cout << grade << endl;
else cout << grade << 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 最大化中位数 二分搜索 以后需要慢慢体会
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 (优先队列)
http://poj.org/problem?id=2010 "Moo U"大学有一种非常严格的入学考试(CSAT) ,每头小牛都会有一个得分.然而,"Moo U&quo ...
- POJ 2010 - Moo University - Financial Aid 初探数据结构 二叉堆
考虑到数据结构短板严重,从计算几何换换口味= = 二叉堆 简介 堆总保持每个节点小于(大于)父亲节点.这样的堆被称作大根堆(小根堆). 顾名思义,大根堆的数根是堆内的最大元素. 堆的意义在于能快速O( ...
- 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 ...
- POJ 2010 Moo University - Financial Aid 优先队列
题意:给你c头牛,并给出每头牛的分数和花费,要求你找出其中n(n为奇数)头牛,并使这n头牛的分数的中位数尽可能大,同时这n头牛的总花费不能超过f,否则输出-1. 思路:首先对n头牛按分数进行排序,然后 ...
- POJ 2010 Moo University - Financial Aid (优先队列)
题意:从C头奶牛中招收N(奇数)头.它们分别得分score_i,需要资助学费aid_i.希望新生所需资助不超过F,同时得分中位数最高.求此中位数. 思路: 先将奶牛排序,考虑每个奶牛作为中位数时,比它 ...
随机推荐
- Blob未完成(待优化)
/**************************************************/ /* Author : Anby */ /* Using :兼容powerBuilder中的B ...
- 终端I/O之stty命令
所有的终端选项标志,在程序中都可用tcgetattr和tcsetattr函数(http://www.cnblogs.com/nufangrensheng/p/3576682.html)进行检查和更改. ...
- redis的实现过程
1下载redis的安装包并按照操作安装 2开启 右击我的电脑→管理→服务→站到redis service服务 将其开启 注意:redis服务开启后其默认的ip和端口号为127.0.0.1:6379 3 ...
- Game: Map Design Considerations 游戏地图设计指南
依据前文伏击战场景手稿, 用Tile Studio "草草"制作出该场景的地图: 生成的C源码: #ifndef _open_war_1Gfx_c #define _open_wa ...
- IDEA社区版运行并发布web项目
IDEA社区版相对收费版少了很多功能,其中包括tomcat等web服务器的支持.网上大部分的IDEA web应用发布教程都是基于收费版的,社区版并没有这么直接的图形化工具可以运行或发布web应用.幸运 ...
- Linux上安装Mysql+Apache+Php
一.安装Mysql 1.卸载默认的mysql yum -y remove mysql-libs-* Removed: mysql-libs.x86_64 0:5.1.73-3.el6_5 卸载成功 ...
- Remoting
一. Remoting基础 什么是Remoting,简而言之,我们可以将其看作是一种分布式处理方式.从微软的产品角度来看,可以说Remoting就是DCOM的一种升级,它改善了很多功能,并极 ...
- 使用 sp_executesql
建议您在执行字符串时,使用 sp_executesql 存储过程而不要使用 EXECUTE 语句.由于此存储过程支持参数替换,因此 sp_executesql 比 EXECUTE 的功能更多:由于 S ...
- java适配器模式随笔记
今天学习了一下java中的适配器模式,在这里做个记录,方便以后查看 什么是适配器,适配就是连接源到目标的中间件,简单的例子就是我们的港水货手机充电器是大三角,我们想要在大陆正常使用我们需要一个转接充电 ...
- JavaScript 编写线程代码引用Concurrent.Thread.js
马上来下载和使用源码吧!假定你已经将下载的源码保存到一个名为Concurrent.Thread.js的文件夹里,在进行任何操作之前,先运行如下程序,这是一个很简单的功能实现: <script t ...