poj 1338 优先队列
生活随笔
收集整理的這篇文章主要介紹了
poj 1338 优先队列
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
用pair來表示推演樹上的結點,用first表示結點的值,用second表示結點是由父結點乘以哪一個因子得到的。
?
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <algorithm> 5 #include <cmath> 6 #include <queue> 7 #include <stack> 8 #include <string> 9 #include <vector> 10 #include <utility> 11 using namespace std; 12 13 typedef pair<__int64, int> node; 14 15 const int maxn = 1e3+505; 16 __int64 ans[maxn]; 17 int n; 18 19 void init() 20 { 21 priority_queue<node,vector<node>,greater<node> > q; 22 q.push(make_pair(1,2)); 23 for(int i=1;i<=1500;i++) 24 { 25 node cur=q.top(); 26 q.pop(); 27 switch(cur.second) 28 { 29 case 2: 30 q.push(make_pair(cur.first*2,2)); 31 case 3: 32 q.push(make_pair(cur.first*3,3)); 33 case 5: 34 q.push(make_pair(cur.first*5,5)); 35 } 36 ans[i]=cur.first; 37 } 38 } 39 40 int main() 41 { 42 init(); 43 while(~scanf("%d",&n)) 44 { 45 if(!n) break; 46 printf("%I64d\n",ans[n]); 47 } 48 return 0; 49 }?
?
?
轉載于:https://www.cnblogs.com/Missa/archive/2012/11/28/2793508.html
總結
以上是生活随笔為你收集整理的poj 1338 优先队列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [备忘]silverlight中关于“复
- 下一篇: jquery 表格(鼠标悬停改变改变行背