UVA - 136Ugly Numbers

    xiaoxiao2021-03-25  131

    题意: 数字包括1,以及2,3,5,2x,3x,5x…..求第1500个丑数

    #include <bits/stdc++.h> using namespace std; #define LL long long priority_queue<LL , vector<LL> , greater<LL> > pq; set<LL> s; int pri[3] = {2,3,5}; int solve() { s.insert(1); pq.push(1); LL temp; for(int i = 1; i <= 1500; i++) { temp = pq.top(); //cout<<temp<<endl; pq.pop(); for(int j = 0; j < 3 ; j++) { LL change = temp*pri[j]; if(s.count(change) == 0) { pq.push(change); s.insert(change); } } } printf("The 1500'th ugly number is %lld.\n",temp); } int main() { solve(); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-6648.html

    最新回复(0)