您的位置:首页 > 大数据 > 人工智能

poj 1338 Ugly Numbers(STL 之 pair)

2012-04-19 21:11 363 查看
题意:

每个数的因子都是有1 2 3 5 组成,求第n 数是几

悲剧的是,不知道怎么回事,电脑上的各个编译器都不能用了

#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
typedef pair<long long ,int> node_type;

int main()
{
int sum[1500];
priority_queue <node_type, vector<node_type>,greater<node_type> > p;
p.push(make_pair(1,2));
for(int i=0;i<1500;i++)
{
node_type q=p.top();
p.pop();
switch(q.second)
{
case 2:p.push(make_pair(q.first*2,2));
case 3:p.push(make_pair(q.first*3,3));
case 5:p.push(make_pair(q.first*5,5));
}
sum[i]=q.first;
}
int n;;
while(cin>>n,n)
cout<<sum[n-1]<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: