UVa 136 Ugly Numbers
2016-04-27 15:45
405 查看
#include<iostream> #include<cstdio> #include<string> #include<map> #include<algorithm> #include<vector> #include<queue> #include<set> #include<cstring> #include<stack> using namespace std; const int arr[]={2,3,5}; typedef long long LL; int main() { priority_queue<LL,vector<LL>,greater<LL> > pq; int i,j; set<LL> S; S.insert(1); pq.push(1); for(i=1;;i++) { LL t=pq.top(); pq.pop(); if(i==1500) { cout<<"The 1500'th ugly number is "<<t<<"."<<endl; break; } for(j=0;j<3;j++) { LL num=t*arr[j]; if(!S.count(num)) { pq.push(num); S.insert(num); } } } return 0; }
相关文章推荐
- 阿里云安装docker的问题
- 列表解析(list comprehension) 与三目运算符
- RHEL系统部署网络yum源
- cmder使用详解
- iOS开发--多线程编程(三)NSOperation
- 支持向量机 - 5 - SMO算法
- 百度地图之覆盖物
- [企业级linux安全管理]- 主机安全管理
- NSNotification
- Android SDK在线更新
- Android SDK在线更新
- 关于ubuntu下的一些软件的安装pycharm ipython-notebook opencv
- 未来数据中心网络的三大武器: SDN、Overlay、VDC
- Android SDK在线更新
- Android SDK在线更新
- Android SDK在线更新
- Android SDK在线更新
- gdb调试
- Linux下安装Activemq-5.11.1
- NSTimer