您的位置:首页 > 其它

joj1751

2010-08-09 23:27 393 查看
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef pair<unsigned long,int> node;

int main()
{
int i,n;
vector<unsigned long> ans;
priority_queue< node , vector<node> , greater<node> > que;//比较因子为greater则小的先出列

que.push(make_pair(1,2));

for(i=0;i<=1600;i++)
{
node temp=que.top();
que.pop();
//注意这里每个case后面没有break,这样处理可以避免重复的插入还保证不会漏掉!!!
switch (temp.second)//此处没有break则如果case 3的话就要执行下一条语句;
{
case 2:que.push(make_pair(temp.first*2,2));
case 3:que.push(make_pair(temp.first*3,3));
case 5:que.push(make_pair(temp.first*5,5));
}
ans.push_back(temp.first);
}

cout<<"The 1500'th ugly number is "<<ans[1499]<<"."<<endl;
return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: