您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: