【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 ...
随机推荐
- Number of Islands II
Given a n,m which means the row and column of the 2D matrix and an array of pair A( size k). Origina ...
- [NOIP 2018]旅行
题目链接 题意简介:现有一个图,小Y要把它走完,每个点只去一次,路径字典序最小. 分析:这道题我认为很重要的一个点就是它的数据范围.它只有两种 m=n-1 或 m=n.我们先考虑第一种:m=n-1也就 ...
- ueditor从word粘贴公式
官网地址http://ueditor.baidu.com Git 地址 https://github.com/fex-team/ueditor 参考博客地址 http://blog.ncmem.com ...
- 西门子二次开发--HMI failed to start
一.Sinumerik二次开发错误:HMI failed to start. HMI--SL Framework reported error: GUI Component could not be ...
- leetcode解题报告(22):Two Sum II - Input array is sorted
描述 Given an array of integers that is already sorted in ascending order, find two numbers such that ...
- Input类中常用的验证方式
Deolin一般将Input类对象作为POST请求方法的参数, Input类的域与前端的数据结构一一对应,由于后端不应该相信前端传过来的任何数据, 所以前端的数据对象先绑定到Input对象中,通过JS ...
- codeforces626F
CF626F Group Projects 有n个学生,每个学生有一个能力值ai.现在要把这些学生分成一些(任意数量的)组,每一组的“不和谐度”是该组能力值最大的学生与能力值最小的学生的能力值的差. ...
- linux 网络带宽和延时测试
Linux下使用qperf命令来测试网络带宽和网络延迟 参考文章:https://access.redhat.com/solutions/2122681 若是没有安装qperf命令,请使用yum 安装 ...
- ASP.NET进行请求转发
前言 前两天将网站的部分功能在小程序上实现,网站的后台是http,没有配置域名和安全证书,小程序的线上版本是无法访问的,因此需要从配有域名和安全证书的站点进行转发.即小程序请求A,A转发请求到B,B获 ...
- ngx.shared.DICT.get 详解
ngx.shared.DICT.get 原文: ngx.shared.DICT.get syntax: value, flags = ngx.shared.DICT:get(key) context: ...