Uva136——Ugly Numbers
2015-10-29 23:03
288 查看
#include <iostream> #include <vector> #include <queue> #include <set> #include <cstdio> using namespace std; typedef long long LL; const int num[3] = {2, 3, 5}; int main() { priority_queue<LL, vector<LL>, greater<LL> > que; set<LL> s; que.push(1); s.insert(1); for(int i = 1; ; i++) { LL x = que.top(); que.pop(); if(i == 1500) { cout << "The 1500'th ugly number is " << x << ".\n"; break; } for(int j = 0; j < 3; j++) { LL x2 = x * num[j]; if(!s.count(x2)) { s.insert(x2); que.push(x2); } } } return 0; }
相关文章推荐
- 第二百一十天 how can I 坚持
- PHP开发环境之WAMP独立安装
- Java中的回调机制
- iOS开发UI篇—程序启动原理和UIApplication
- 1.7-nagios配置邮件告警
- Uva400——Unix ls
- 如何在github上传自己的项目
- 十天冲刺---Day1
- Java String API
- Java String API
- 欢迎使用CSDN-markdown编辑器
- 关于修改 commit_write 提升性能的一点理解
- 记。。关于python处理表单
- C语言文法
- LeetCode Unique Paths (简单DP)
- LeetCode 刷题: 两个二叉树节点的最近公共节点Least Common Ancestor
- 1.6-nagios监控客户端-2
- 关注博客:夏冰加密软件技术博客(加密相关技术博客)
- java.lang.RuntimeException: java.lang.NullPointerException...的错误
- AngularJs angular.identity和angular.noop