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;}
#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;}
相关文章推荐
- joj1751
- 网页编程之验证码识别技术 http://www.meiyisi.com/article.asp?id=1751
- 关于JOJ 2042的启发——一种写程序计算幂函数的方法
- JOJ 1055: Cog-Wheels 解题报告
- JOJ 1182: Lotto
- JOJ 2650: 礼物
- joj 1279 最长上升子序列 NLogN
- joj 2652 数组操作
- joj 1019解题报告
- JOJ1076 && POJ1039 Pipe 经典计算几何
- joj 2526: medic(dp 背包 )
- JOJ2519 Find the longest section(位运算 +(前缀和?))
- JOJ 2558 / HDU 2757 (Ocean Currents) 解题纠错
- joj1035
- joj2243
- joj 2672 Hanoi Tower Once More 有向无环图的最小路径覆盖=N-最大匹配
- joj 1387
- JOJ2026:Divide the Birthday Cake
- joj 2431: Shift and Increment
- joj1013 Polynomial Multiplication