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

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

枚举中位数+优先级队列预处理前x个数选n个最小和

#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int maxn=100000+10;int n,c;LL f;struct X{ LL s; LL v;} t[maxn];priority_queue
q;LL dp1[maxn],dp2[maxn];bool cmp(const X&a,const X&b){ return a.s
=n) { if(n==1) { for(int i=1; i<=c; i++) if(t[i].v<=f) ans=t[i].s; } else { while(!q.empty()) q.pop(); int num=(n-1)/2; for(int i=1; i<=num; i++) dp1[num]=dp1[num]+t[i].v,q.push(t[i].v); for(int i=num+1; i<=c; i++) { if(t[i].v>=q.top()) dp1[i]=dp1[i-1]; else { dp1[i]=dp1[i-1]-(q.top()-t[i].v); q.pop(); q.push(t[i].v); } } while(!q.empty()) q.pop(); for(int i=c; i>=c-num+1; i--) dp2[c-num+1]=dp2[c-num+1]+t[i].v,q.push(t[i].v); for(int i=c-num; i>=1; i--) { if(t[i].v>=q.top()) dp2[i]=dp2[i+1]; else { dp2[i]=dp2[i+1]-(q.top()-t[i].v); q.pop(); q.push(t[i].v); } } for(int i=1; i<=c; i++) { if(i-1

 

转载于:https://www.cnblogs.com/zufezzt/p/5352195.html

你可能感兴趣的文章
C# 存储过程
查看>>
软件体系结构的第二次实验
查看>>
无聊记记
查看>>
ODI Scenario 场景
查看>>
操作JSON对象
查看>>
iOS 模态视图,视图之间的切换
查看>>
iptables
查看>>
.NET自动识别GB2312与UTF-8编码的文件
查看>>
Linux下apache日志分析与状态查看方法
查看>>
hdu2412(树形dp)
查看>>
js返回函数, 函数名后带多个括号的用法及join()的注意事项
查看>>
【NOIP2007】矩阵取数
查看>>
关于VIM在Win10下的无意义折腾
查看>>
ibatis example Class 使用
查看>>
android的触摸事件(转)
查看>>
springMVC与struts2的区别
查看>>
【DB2数据库在windows平台上的安装】
查看>>
课后作业-阅读任务-阅读笔记-4
查看>>
Yii2数据缓存详解
查看>>
02Scala-函数定义、流程控制、异常处理入门实战
查看>>