原题链接:http://poj.org/problem?id=1338

优先队列的应用,如下:

 #include<cstdio>
#include<cstdlib>
#include<queue>
#include<functional>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max_N = ;
ll ans[Max_N];
void init(){
int arr[] = { , , };
priority_queue<ll, vector<ll>, greater<ll> > que;
que.push();
for (int i = ; i <= ;){
ll t = que.top();
que.pop(), ans[i] = t;
if (ans[i] == ans[i - ]){
continue;
} else {
i++;
}
for (int j = ; j < ; j++) que.push((ll)(t * arr[j]));
}
}
int main(){
init();
int n;
while (~scanf("%d", &n) && n) printf("%lld\n", ans[n]);
return ;
}

poj 1338 Ugly Numbers的更多相关文章

  1. Poj 1338 Ugly Numbers(数学推导)

    一.题目大意 本题要求写出前1500个仅能被2,3,5整除的数. 二.题解 最初的想法是从1开始检验该数是否只能被2,3,5整除,方法是这样的,对于一个数,如果它能被2整除,就除以2,如果它能被3整除 ...

  2. poj 1338 Ugly Numbers(丑数模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...

  3. 51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先 ...

  4. Poj 2247 Humble Numbers(求只能被2,3,5, 7 整除的数)

    一.题目大意 本题要求写出前5482个仅能被2,3,5, 7 整除的数. 二.题解 这道题从本质上和Poj 1338 Ugly Numbers(数学推导)是一样的原理,只需要在原来的基础上加上7的运算 ...

  5. Ugly Numbers(STL应用)

    题目链接:http://poj.org/problem?id=1338 Ugly Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  6. [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)

    再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...

  7. 递推(三):POJ中的三道递推例题POJ 1664、POJ 2247和POJ 1338

    [例9]放苹果(POJ 1664) Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. In ...

  8. [POJ1338]Ugly Numbers

    [POJ1338]Ugly Numbers 试题描述 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...

  9. Ugly Numbers

    Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21918 Accepted: 9788 Descrip ...

随机推荐

  1. asp.net 配置 X-Frame-Options

    近日网站在安全检查,送检的网站被反馈有以下问题 X-Frame-Options Header未配置 漏洞描述: 弱点描述: X-Frame-Options HTTP响应头可以指示浏览器是否允许当前网页 ...

  2. ZoneMinder配置与使用

    ZoneMinder是一套基于Linux操作系统的摄像机的视像数据监控的应用软件.应用范围广泛,包括商业或家居防盗等.ZoneMinder支持单一或多台视像镜头应用,包括摄取.分析.记录.和监视来源, ...

  3. psutil

    tar -zxvf psutil-2.1.3.tar.gz cd psutil-2.1.3 python setup.py install 安装是出现报错 error: command 'gcc' f ...

  4. CSS常用的属性命名

    页头:header   如:#header{属性:属性值;}或.header{属性:属性值;},也许你需要了解class与id区别及用法 登录条:loginBar         标志:logo   ...

  5. How to index email and attachments in nsf files?

    My colleague she ask me why Intella could not handle Lotus Notes nsf e-mail archive files. I told he ...

  6. IEF could not decode Chinese character in IE history well

    My friend is working on some case, and she looks not in the mood. I ask her what's going on. She wan ...

  7. 通过Migration在EF6中用多个DbContext

    通过Migration在EF6中用多个DbContext EF EF6 C# Migration 通过Migration在EF6中用多个DbContext 前言 实现目标 设置多数据上下文 更新数据脚 ...

  8. POJ C程序设计进阶 编程题#1:计算矩阵边缘之和

    编程题#1:计算矩阵边缘元素之和 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB ...

  9. 03-图片浏览器(plist的简单应用)

    ViewController.h文件中: @interface ViewController : UIViewController - (IBAction)sliderValueChange:(UIS ...

  10. 设置Safari浏览器在标签栏上打开新窗口,而不是弹出一个新窗口

    打开Safari浏览器的偏好设置,如图: 打开“标签”一项,如上图.在“在标签(而不是窗口)中打开页面:”中设置.