UVa 136 Ugly Numbers
来源:互联网 发布:薇姿适合什么年龄知乎 编辑:程序博客网 时间:2024/05/16 07:37
Description
丑数是不能被2,3,5以外其他质数整除的数。
找第1500个丑数
Algorithm
生成丑数
每次取最小的丑数x,然后将2x,3x,5x加入优先队列
Code
#include <cstdio>#include <iostream>#include <queue>#include <vector>#include <set>using namespace std;typedef long long ll;const int a[3] = {2, 3, 5};int main(){ priority_queue<ll, vector<ll>, greater<ll> > pq; set<ll> s; pq.push(1); s.insert(1); ll x; for (int i = 1; i <= 1500; i++) { x = pq.top(); pq.pop(); for (int j = 0; j < 3; j++) { ll x2 = x * a[j]; if (!s.count(x2)) { s.insert(x2); pq.push(x2); } } } cout << "The 1500'th ugly number is " << x << "." << endl;}
0 0
- UVa 136 - Ugly Numbers
- UVa 136 - Ugly Numbers
- UVa 136 - Ugly Numbers
- UVA - 136 Ugly Numbers
- UVA 136 Ugly Numbers
- Uva - 136 - Ugly Numbers
- UVA 136 Ugly Numbers
- UVA 136 Ugly Numbers
- UVA - 136 Ugly Numbers
- UVA 136 Ugly Numbers
- UVa 136 Ugly Numbers
- UVa 136 Ugly Numbers
- UVA - 136 Ugly Numbers
- Uva 136 - Ugly Numbers
- UVa 136 Ugly Numbers
- UVA-136 Ugly Numbers
- UVA 136 Ugly Numbers
- Ugly Numbers, UVa 136
- 我们为什么不使用NSLog
- [LeetCode]120. Triangle
- 史上最全最强SpringMVC详细示例实战教程
- 用Vc++写的音视频即时通话程序(部分代码)
- AndroidStudio中如何在android style文件中使用自定义属性
- UVa 136 Ugly Numbers
- [剑指offer]数组中的逆序对
- 【bzoj 2502】清理雪道(有上下界的网络流)
- Hibernate Restrictions.or 以及 Restrictions.disjunction实现逻辑或
- 实现1-1000中所有素数的和
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
- DHCP Relay Configuration on SonicOS
- [剑指offer]两个链表公共节点
- django.contirb.auth-认证