博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2010 Moo University - Financial Aid
阅读量:6834 次
发布时间:2019-06-26

本文共 3686 字,大约阅读时间需要 12 分钟。

Moo University - Financial Aid
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 9578   Accepted: 2785

Description

Bessie noted that although humans have many universities they can attend, cows have none. To remedy this problem, she and her fellow cows formed a new university called The University of Wisconsin-Farmside,"Moo U" for short. 
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

* Line 1: Three space-separated integers N, C, and F 
* 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

* Line 1: A single integer, the maximum median score that Bessie can achieve. If there is insufficient money to admit N calves,output -1. 

Sample Input

3 5 7030 2550 2120 205 1835 30

Sample Output

35

Hint

Sample output:If Bessie accepts the calves with CSAT scores of 5, 35, and 50, the median is 35. The total financial aid required is 18 + 30 + 21 = 69 <= 70. 

Source

/** @Author: Lyucheng* @Date:   2017-07-20 09:47:21* @Last Modified by:   Lyucheng* @Last Modified time: 2017-07-20 17:56:01*//* 题意:给你C个奶牛参加考试的分数,和需要奖学金的数目,让你从中选N头奶牛,需要总奖学金的数目不超过F,并且分数的    中位数最大 思路:按照分数排序,二分中位数,有个问题就是判断问题可能会超时 细节:判断的时候还有给他排一下序,这样才能去到最小的,还要特判n==1的时候*/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAXN 100005using namespace std;struct Node{ int score,cost; bool operator < (const Node & other) const{ if(score==other.score) return cost
=pos[i].cost){ if(pos[i].score==node[x].score){ sum-=pos[i].cost; cnt2++; }else if(pos[i].score
node[x].score){ if(cnt1
=n-1) return true; return false;}int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(scanf("%d%d%d",&n,&c,&f)!=EOF){ for(int i=1;i<=c;i++){ scanf("%d%d",&node[i].score,&node[i].cost); } if(n==1){ sort(node+1,node+c+1,cmp); bool f=false; for(int i=c;i>=1;i--){ if(node[i].cost<=f){ printf("%d",node[i].score); f=true; break; } } if(f==false){ puts("-1"); } continue; } sort(node+1,node+c+1); int l=1,r=c,mid; int res=-1; while(l<=r){ mid=(l+r)/2; if(ok(mid)==true){ l=mid+1; res=node[mid].score; }else{ r=mid-1; } } printf("%d\n",res); } return 0;}

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/7212601.html

你可能感兴趣的文章
Kotlin的一次lambda探险
查看>>
关于js的星星点点(构造函数和普通函数及class)
查看>>
两个超详细的python爬虫技能树(思维导图)
查看>>
PostCSS真的太好用了!
查看>>
微信热修复 tinker 及 tinker server 快速接入
查看>>
闫燕飞:Kafka的高性能揭秘及优化
查看>>
Dionaea蜜罐指南
查看>>
Redux源码分析--bindActionCreators篇
查看>>
iOS 网络编程(二)TCP协议小结
查看>>
OkHttp3.0解析——谈谈内部任务分发器dispatcher
查看>>
HTTP Header简介
查看>>
六、TextInput
查看>>
SSH的配置与管理
查看>>
Java并发编程----阻塞队列
查看>>
03 前端HTTP协议(图解HTTP) 之 HTTP报文内的HTTP信息
查看>>
linux 定时器怎么用? crontab 基础
查看>>
报警系统QuickAlarm之频率统计及接口封装
查看>>
iOS开发runtime实现KVO
查看>>
LeetCode 014&053
查看>>
if(3 == true) ?
查看>>