您的位置:首页 > 其它

UVa_136Ugly_Number

2015-05-27 22:10 239 查看

#include <iostream>

#include <set>

#include <queue>

#include <algorithm>

using namespace std;

typedef long long LL;

const int coeff[3] = { 2, 3, 5 };

int main()

{

set<LL> dict;

priority_queue<LL> Q;

int result = 0;

Q.push(1);

dict.insert(1);

for (int i = 0; ; i++)

{

LL x;

x = Q.top();

Q.pop();

if (i == 1500)

cout << x<<endl;

for (int j = 0; j < 3; j++)

{

LL x2 = x*coeff[j];

if (!dict.count(x2))

{

dict.insert(x2);

Q.push(x2);

}

}



}

return 0;

}

程序没有问题,超时。。。还需要改进
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: