博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj - 1442 Black Box
阅读量:7209 次
发布时间:2019-06-29

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

好久没刷题了,脑子都锈掉了。这题是用优先队列做的,而且是STL里的。STL里的priority_queue默认是大堆,你可以理解为递减数列。如果要用小堆需要一点参数,我只记得一个简单些的方法:priority_queue<T, vector<T>, greater<T> >,T表示数据类型,这样就是一个小堆了。做这题时我“参考”了别人的代码,不过原版的注释写得很混乱,不知道是不是用来忽悠人的。以下是代码:

1 #include 
2 #include
3 using namespace std; 4 int A[30010],u[30010]; 5 int main() 6 { 7 int m,n,i,j,t; 8 while(cin>>m>>n) 9 {10 priority_queue
> small;11 priority_queue
,greater
> big;12 for(i = 0; i < m; i++)13 cin>>A[i];14 for(j = 0; j < n; j++)15 cin>>u[j];16 j = 0;17 for(i = 0; i < m && j < n; i++)18 {19 if(small.empty())20 big.push(A[i]);21 else if(A[i] < small.top())22 {23 t = small.top();24 small.pop();25 big.push(t);26 small.push(A[i]);27 }28 else big.push(A[i]);29 while(u[j] == i+1)30 {31 j++;32 t = big.top();33 big.pop();34 cout<
<

 

转载于:https://www.cnblogs.com/lzxskjo/archive/2012/07/10/2585449.html

你可能感兴趣的文章
nodejs发展
查看>>
Fragment过度动画分析一
查看>>
UBI文件系统简介
查看>>
《现代操作系统》精读与思考笔记 第一章 引论
查看>>
System.out.print实现原理猜解
查看>>
每日英语:The Invasion of the Online Tutors
查看>>
codepage IMLangCodePages
查看>>
Leetcode: Valid Parentheses
查看>>
JavaScript Structure
查看>>
java 流媒体服务器Red5 FQA
查看>>
mysql--SQL编程(关于mysql中的日期) 学习笔记2
查看>>
jquery 请求jsp传递json数据的方法
查看>>
Repeater绑定事件ItemDataBound中获取数据库中数据
查看>>
草长莺飞,总归一字
查看>>
HDOJ 2097
查看>>
计算机学科漫谈
查看>>
mac下配置openfire
查看>>
自定义控件实现(转)
查看>>
如何确认访客所在的国家
查看>>
跟着8张思维导图学习javascript
查看>>