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;
}
程序没有问题,超时。。。还需要改进
#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;
}
程序没有问题,超时。。。还需要改进
相关文章推荐
- uva 10624 Super Number 险险的过了。。。
- UVA 11651 - Krypton Number System(DP+矩阵快速幂)
- UVA 11885 - Number of Battlefields(斐波那契)
- UVA 10689 - Yet another Number Sequence(矩阵快速幂)
- 数学专项number_theory:UVa 10236
- UVa 10077 - The Stern-Brocot Number System
- UVA11651 Krypton Number System【矩阵快速幂】
- UVa 10689 - Yet another Number Sequence
- UVA 10689 Yet another Number Sequence
- UVa 11371 Number Theory for Newbies (water ver.)
- UVA 10624 - Super Number(DFS)
- UVa 10624 - Super Number, Rujia Liu的神题(四)
- UVA - 10624 Super Number(回溯)
- UVA 10077 The Stern-Brocot Number System
- UVA 4683 - Find The Number
- UVA 10624 Super Number
- UVA 11651 Krypton Number System(矩阵加速DP)
- UVA 4683 - Find The Number
- UVA 10689 Yet another Number Sequence 矩阵快速幂 水呀水
- UVA 10624 - Super Number