zoukankan      html  css  js  c++  java
  • poj 1338 Ugly Numbers

     原题链接: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
    ", ans[n]);
    30     return 0;
    31 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    EM
    te2
    te
    XLnet
    GPT
    40.Properties
    38.特殊操作流
    37.I/O流
    35.File
    day68日考
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4462698.html
Copyright © 2011-2022 走看看