poj 1338 Ugly Numbers

原题链接:http://poj.org/problem?id=1338

优先队列的应用,如下:

 #include<cstdio>
#include<cstdlib>
#include<queue>
#include<functional>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max_N = ;
ll ans[Max_N];
void init(){
int arr[] = { , , };
priority_queue<ll, vector<ll>, greater<ll> > que;
que.push();
for (int i = ; i <= ;){
ll t = que.top();
que.pop(), ans[i] = t;
if (ans[i] == ans[i - ]){
continue;
} else {
i++;
}
for (int j = ; j < ; j++) que.push((ll)(t * arr[j]));
}
}
int main(){
init();
int n;
while (~scanf("%d", &n) && n) printf("%lld\n", ans[n]);
return ;
}
上一篇:javaweb学习总结(四十五)——监听器(Listener)学习二


下一篇:10分钟快速搞定pandas