题意的话,就看其他人的吧


概括:二分中位数

大体上便是二分一个中位数,带入检验,若分数比他小的有\(\lfloor n/2 \rfloor\)个,分数比他的大的也有这么多,而且贪心的买,花费小于预算。

便带入到数作为中位数是可以的。记录并进行下一次二分

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using std::sort;
const int maxn=101000;
struct node
{
int id;
long long score;
long long cost;
node ( ) { id=score=cost=0; }
};
node base[maxn],pas[maxn];
int rank[maxn];
long long n,c,f;
int compare1(const node &a,const node &b)
{
if(a.score!=b.score) return a.score<b.score;
return a.cost<b.cost;
}
int compare2(const node &a,const node &b)
{
return a.cost<b.cost;
}
int mk_it(int v)
{
long long T1=0,T2=0,Tot=base[v].cost;//T1为前半部分选取的个数,T2为后半部分选取的个数,Tot为总花费
for(int i=1;i<=c&&Tot<=f&&T1+T2+1<n;i++)
{
int Id=pas[i].id,F=0;//F是用来防止同一个分数,在下面被选了两次
if(Id==base[v].id) continue;
if((rank[Id]<rank[base[v].id]||pas[i].score==base[v].score)&&T1<(n>>1))
{
++T1;F=1;
Tot+=pas[i].cost;
}
if((rank[Id]>rank[base[v].id]||pas[i].score==base[v].score)&&T2<(n>>1)&&!F)
{
++T2;
Tot+=pas[i].cost;
}
}
return T1+T2+1==n&&Tot<=f;//返回是否可行
}
int main()
{
scanf("%lld%lld%lld",&n,&c,&f);
for(int i=1;i<=c;i++)
{
scanf("%lld%lld",&base[i].score,&base[i].cost);
base[i].id=i;
}
sort(base+1,base+1+c,compare1);//按照分数排序
for(int i=1;i<=c;i++) rank[base[i].id]=i,pas[i]=base[i];//记录排名(检验时用到)
sort(pas+1,pas+1+c,compare2);//按照价钱排序
int l=1,r=c;
long long ans=-1;
while(l<=r)//二分
{
int mid=(l+r)>>1;
if(mk_it(mid))
ans=base[mid].score,l=mid+1;
else
r=mid-1;
}
printf("%lld",ans);
}

Poj2010 Moo University - Financial Aid的更多相关文章

  1. poj2010 Moo University - Financial Aid 优先队列

    Description Bessie noted that although humans have many universities they can attend, cows have none ...

  2. POJ2010 Moo University - Financial Aid(二分法)

    题目地址 分析:如果用二分法,关键是score和aid分开排序,score排序是为了充分利用中位数的性质,这样就可以确定m左右必须各选N/2个,到这之后有人是用dp求最优解,可以再次按照aid排序一次 ...

  3. 【POJ - 2010】Moo University - Financial Aid(优先队列)

    Moo University - Financial Aid Descriptions 奶牛大学:奶大招生,从C头奶牛中招收N(N为奇数)头.它们分别得分score_i,需要资助学费aid_i.希望新 ...

  4. Divide and conquer:Moo University - Financial Aid(POJ 2010)

    Moo University - Financial Aid 其实是老题了http://www.cnblogs.com/Philip-Tell-Truth/p/4926008.html 这一次我们换二 ...

  5. Moo University - Financial Aid

    Moo University - Financial Aid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6020 Accep ...

  6. poj 2010 Moo University - Financial Aid

                                                                                                Moo Univ ...

  7. POJ 2010 Moo University - Financial Aid( 优先队列+二分查找)

    POJ 2010 Moo University - Financial Aid 题目大意,从C头申请读书的牛中选出N头,这N头牛的需要的额外学费之和不能超过F,并且要使得这N头牛的中位数最大.若不存在 ...

  8. poj 2010 Moo University - Financial Aid 最大化中位数 二分搜索 以后需要慢慢体会

    Moo University - Financial Aid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6599   A ...

  9. poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)

    Description Bessie noted that although humans have many universities they can attend, cows have none ...

随机推荐

  1. Django之路由、模板和模型系统 (转载)

    一.路由系统 浏览器会自动给url后加一个“/” django会自动给路由的正则表达式前面加一个“/” django会给任何不带“/”结尾的url语句添加“/”(可设置) 短路路由规则:匹配到第一条就 ...

  2. 如何正确实现 IDisposable 接口

    MSDN建议按照下面的模式实现IDisposable接口: public class Foo: IDisposable { public void Dispose() { Dispose(true); ...

  3. 批量删除微博的js代码

    清空微博,网上找了一段js代码,试了下,还行. var fileref=document.createElement('script') fileref.setAttribute("type ...

  4. 使用spring tool suite(STS)工具创建spring boot项目和出现错误后的处理

    一.先下载配置maven环境 1.下载地址:http://maven.apache.org/download.cgi windows下下载zip文件 2.解压后放到某个文件目录下 3.配置环境变量 ( ...

  5. JavaScript中sort()方法

    sort()方法主要是用于对数组进行排序,默认情况下该方法是将数组元素转换成字符串,然后按照ASC码进行排序,这个大家都能理解,但如果数组元素是一个Object呢,转不了字符串,难道不能进行排序?答案 ...

  6. 面试准备之三Django知识

    Django请求流程 MTV模式 路由 视图 ORM 模板

  7. 异步nodejs代码的同步样子写法样例

    异步nodejs代码的同步样子写法样例 js的异步嵌套太深代码将不好看.尤其在用node的时候这种情况会大量出现. 这里用node连接redis,做一个用户注册的简单例子来说明.例如用redis做存储 ...

  8. SQL Server ->> Memory Allocation Mechanism and Performance Analysis(内存分配机制与性能分析)之 -- Minimum server memory与Maximum server memory

    Minimum server memory与Maximum server memory是SQL Server下配置实例级别最大和最小可用内存(注意不等于物理内存)的服务器配置选项.它们是管理SQL S ...

  9. 使用CoreImage教程

    使用CoreImage教程 CoreImage包含有很多实用的滤镜,专业处理图片的库,为了能看到各种渲染效果,请使用如下图片素材. 现在可以开始教程了: #define FIX_IMAGE(image ...

  10. GCC the GNU

         GCC简单使用 -v/-v/--version 查看gcc版本号 python@ubuntu:~$ gcc -v -I 指定头文件目录,注意-I和之间没有空格 1 #include<s ...