标签:
原题链接:http://poj.org/problem?id=1338
优先队列的应用,如下:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<queue> 4 #include<functional> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 typedef long long ll; 9 const int Max_N = 1510; 10 ll ans[Max_N]; 11 void init(){ 12 int arr[4] = { 2, 3, 5 }; 13 priority_queue<ll, vector<ll>, greater<ll> > que; 14 que.push(1); 15 for (int i = 1; i <= 1500;){ 16 ll t = que.top(); 17 que.pop(), ans[i] = t; 18 if (ans[i] == ans[i - 1]){ 19 continue; 20 } else { 21 i++; 22 } 23 for (int j = 0; j < 3; j++) que.push((ll)(t * arr[j])); 24 } 25 } 26 int main(){ 27 init(); 28 int n; 29 while (~scanf("%d", &n) && n) printf("%lld\n", ans[n]); 30 return 0; 31 }
标签:
原文地址:http://www.cnblogs.com/GadyPu/p/4462698.html