您的位置:首页 > 其它

UVa 136 Ugly Numbers

2016-04-27 15:45 405 查看
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<stack>
using namespace std;

const int arr[]={2,3,5};

typedef long long  LL;

int main()
{
priority_queue<LL,vector<LL>,greater<LL> > pq;
int i,j;
set<LL> S;
S.insert(1);
pq.push(1);
for(i=1;;i++)
{
LL t=pq.top();
pq.pop();
if(i==1500)
{
cout<<"The 1500'th ugly number is "<<t<<"."<<endl;
break;
}
for(j=0;j<3;j++)
{
LL num=t*arr[j];
if(!S.count(num))
{
pq.push(num);
S.insert(num);
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: