首页 > 其他 > 详细

POJ1338丑数(uva136)

时间:2017-01-23 22:55:57      阅读:316      评论:0      收藏:0      [点我收藏+]

UVA书上用的set,poj上这个题我用的vector。

 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 #include <algorithm>
 5 #include <cstdio>
 6 #include <cstdlib>
 7 #include <cstring>
 8 #include <queue>
 9 #include <cstdio>
10 #include <cstdlib>
11 #include <set>
12 #include <sstream>
13 
14 using namespace std;
15 const int a[3]={2,3,5};
16 typedef long long LL;
17 
18 int main()
19 {
20     priority_queue<LL, vector<LL>,greater<LL> > pq;
21     vector<LL> s;
22     pq.push(1);
23     s.push_back(1);
24     int i,j,m;
25     for(i=1;;i++)
26     {
27         LL y = pq.top();
28         pq.pop();
29         if(i==1500)break;
30         for(j=0;j<3;j++)
31         {
32             LL x = y*a[j];
33             if(find(s.begin(),s.end(),x)==s.end())
34             {
35                 s.push_back(x);
36                 pq.push(x);
37             }
38         }
39     }
40     sort(s.begin(),s.end());
41     while(cin >> m && m)
42         cout << s[m-1] << endl;
43     return 0;
44 }

 

POJ1338丑数(uva136)

原文:http://www.cnblogs.com/HsiaoYeekwan/p/6345083.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!