丑数 (using priority_queue) UVA
来源:互联网 发布:淘宝联盟微信打不开 编辑:程序博客网 时间:2024/05/29 19:34
#include <bits/stdc++.h>using namespace std;typedef long long ll;int dir[3]={2,3,5};int main(void){ priority_queue<ll,vector<ll>,greater<ll> >pq; set<ll> s; pq.push(1); s.insert(1); for(int i=1;i<=1500;i++) { ll x=pq.top();pq.pop(); //printf("%I64d\n",x); if(i==1500) { //printf("The 1500'th ugly number is %I64d.\n",x); cout<<"The 1500'th ugly number is "<<x<<".\n"; break; } for(int j=0;j<3;j++) { ll nx=x*dir[j]; if(!s.count(nx)) { s.insert(nx); pq.push(nx); } } } return 0;}//set s 作为标记功能,s.insert()实现,s.cout()判断是否出现过,比普通开数组能够节约很多的空间,很有好处。priority_queue<ll,vector<ll>,greater<ll> >pq中greater使原本top是最大的,变成最小的,效果和greater反一下,记住就好。
阅读全文
0 0
- 丑数 (using priority_queue) UVA
- UVa 136 丑数
- uva 136 丑数
- Uva 136 丑数
- uva 136 丑数
- UVA 136 丑数
- UVa 136 丑数
- 丑数 UVa 136
- UVA 136 丑数
- 丑数 uva-136 丑数
- 丑数(UVa 136)
- uva 136 丑数 STL
- hdu 5878 丑数 STL(pair,priority_queue)
- HDU 1058||Uva 136 丑数
- Ugly Numbers UVA 136 丑数
- Uva 136 Ugly Numbers(丑数)
- hdoj-1058(优先队列)---priority_queue====丑数
- 丑数
- 提高Web端页面加载速度的6个方法
- Java Filter过滤机制详解
- 暑期集训之0和5
- 一个高级java工程师需要具备什么能力和技术
- Android_不同行为的Fragement的生命周期的变化
- 丑数 (using priority_queue) UVA
- my.cnf推荐配置
- 看了这部剧就是科技圈大赢家_别落伍!
- myEclipse 为什么启动不了tomcat,我的jdk是1.7,
- qtchooser的使用
- 弹性布局辨析
- 深入解读四轴飞行器的硬件设计
- 每天五分钟linux(9)-touch
- java枚举类型与字符串或其他类型的互转