紫书章五例题七 丑数 UVa 136(多种方法,在这里介绍优先级队列)
来源:互联网 发布:李东峰 北京航天数据 编辑:程序博客网 时间:2024/06/05 08:58
priority_queue pq;
其实优先级队列为vector,然后vector里的排序是从小到大,然后pq出队的操作对应的是vector的尾删,所以我们看到的pq的出队的数据是从大到小,大数据优先级大。
因为这里的出队元素并不是最先进队的,所以出队方式由queue 的front()变为了top()
如果要改变其排列顺序的话,和sort函数一样,要对其< 进行重载
然后priority_queue
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <queue>#include <set>using namespace std;#define LL long longint a[]={2,3,5};int main(){ priority_queue<LL,vector<LL> ,greater<LL> > pq; set<LL> s; pq.push(1); s.insert(1); for(int i=1;;i++) { LL x=pq.top(); pq.pop(); if(i == 1500) { printf("The 1500'th ugly number is %d.\n",x); break; } for(int j=0;j<3;j++){ LL x2=x* a[j]; if(!s.count(x2)) { s.insert(x2); pq.push(x2); } } } return 0;}
0 0
- 紫书章五例题七 丑数 UVa 136(多种方法,在这里介绍优先级队列)
- 例题5-7 UVA 136 Ugly Numbers丑数(set+优先队列)
- 丑数(UVa 136)
- UVa 136 丑数
- uva 136 丑数
- Uva 136 丑数
- uva 136 丑数
- UVA 136 丑数
- UVa 136 丑数
- 丑数 UVa 136
- UVA 136 丑数
- 丑数 uva-136 丑数
- uva 136 丑数 STL
- HDU 1058||Uva 136 丑数
- Ugly Numbers UVA 136 丑数
- Uva 136 Ugly Numbers(丑数)
- 丑数(递推||优先队列)
- 紫书章五例题六 团队队列 uva 540(queue)
- 4.2(数组)课程管理
- leetcode441. Arranging Coins
- 1072
- Linux查询安装软件
- 大数据-开发利器
- 紫书章五例题七 丑数 UVa 136(多种方法,在这里介绍优先级队列)
- 霍夫线变换——找出图片中的直线
- android 实时检测网络状态
- 1073
- SMTP协议介绍
- mysql
- 1074
- Unity3DGame学习笔记(5):飞碟修改
- matlab矩阵的一些操作