uva 136 120页

来源:互联网 发布:米惠淘宝返利网 编辑:程序博客网 时间:2024/05/16 10:33
#include <queue>#include <cstdio>#include <iostream>#include <algorithm>#include <set>#define ll long long using namespace std;int a[3]={2,3,5};int main() {    priority_queue<ll ,vector<ll>, greater<ll> > pq;    set<ll> s;    pq.push(1);    s.insert(1);    for(int i=1;;i++) {        if(1500==i) {            printf("The 1500'th ugly number is %lld.\n",pq.top());            break;        }        else {            ll t=pq.top();pq.pop();            for(int j=0;j<3;j++) {                ll num=a[j]*t;                if(!s.count(num)) {                    s.insert(num);                    pq.push(num);                }            }        }    }     return 0;}