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,同时得分中位数最高.求此中位数. 思路: 先将奶牛排序,考虑每个奶牛作为中位数时,比它 ...
随机推荐
- 剑指 offer set 1 二维数组中查找
总结 1. 二维数组搜索题遇到两个了, 一个是 Leetcode 上 search in 2D matrix. 那道题比较简单, 因为下一行的所有元素大于上一行的. 这道题对二维矩阵的要求比较松, 起 ...
- javascript 变量解析
1.JavaScript中,你可以在函数的任何位置声明多个var语句,并且它们就好像是在函数顶部声明一样发挥作用,这种行为称为 hoisting(悬置/置顶解析/预解析).当你使用了一个变量,然后不久 ...
- android学习日记13--数据存储之ContentProvide
3.ContentProvider 数据在Android当中是私有的,当然这些数据包括文件数据和数据库数据以及一些其他类型的数据.ContentProvider实现多应用程序间的数据共享类一般利用Co ...
- mkinitrd 与 mkinitramfs
转载:http://blog.csdn.net/mayouyang/article/details/3997849 在进行内核编译时,需要进行制作initrd.img.在Fedora下面一般是用mki ...
- C#操作XML(带命名空间)
之前文章讲述了使用c# xpath如何操作xml文件,在实际开发项目中,遇到的很多xml文件都是带有命名空间的,如果还是用之前的代码获取,那将获取到null.本文讲解操作代码有命名空间的Xml文件,以 ...
- C# 之 FileSystemWatcher事件多次触发的解决方法
1.问题描述 程序里需要监视某个目录下的文件变化情况: 一旦目录中出现新文件或者旧的文件被覆盖,程序需要读取文件内容并进行处理.于是使用了下面的代码: public void Initial() { ...
- js的2种继承方式详解
js中继承可以分为两种:对象冒充和原型链方式 一.对象冒充包括三种:临时属性方式.call()及apply()方式1.临时属性方式 复制代码代码如下: function Person(name){ ...
- 转 如何使用velocity模板引擎开发网站
基于 Java 的网站开发,很多人都采用 JSP 作为前端网页制作的技术,尤其在是国内.这种技术通常有一些问题,我试想一下我们是怎样开发网站的,通常有几种方法: 1:功能确定后,由美工设计网页的UI( ...
- 开启AsyncTask从网络加载图片
/*AsyncTask 异步任务即做一些简单的异步处理 :是handle与线程池的封装 * 第一个泛型:参数类型泛型 * 第二个泛型:更新进度泛型 * 第三个泛型:onProgressUpdate的返 ...
- BeginInvoke、ThreadPool、Task三类异步方法的区别和速度比较
速度(最快为1) 返回值 多参数 等待在时限内完成 超时后结束 ThreadPool.UnsafeQueueUserWorkItem() 1 非原生支持1 非原生支持 非原生支持3 不支持 Thr ...