poj 1338 Ugly Numbers
原题链接: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的更多相关文章
- Poj 1338 Ugly Numbers(数学推导)
一.题目大意 本题要求写出前1500个仅能被2,3,5整除的数. 二.题解 最初的想法是从1开始检验该数是否只能被2,3,5整除,方法是这样的,对于一个数,如果它能被2整除,就除以2,如果它能被3整除 ...
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- 51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先 ...
- Poj 2247 Humble Numbers(求只能被2,3,5, 7 整除的数)
一.题目大意 本题要求写出前5482个仅能被2,3,5, 7 整除的数. 二.题解 这道题从本质上和Poj 1338 Ugly Numbers(数学推导)是一样的原理,只需要在原来的基础上加上7的运算 ...
- Ugly Numbers(STL应用)
题目链接:http://poj.org/problem?id=1338 Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...
- 递推(三):POJ中的三道递推例题POJ 1664、POJ 2247和POJ 1338
[例9]放苹果(POJ 1664) Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. In ...
- [POJ1338]Ugly Numbers
[POJ1338]Ugly Numbers 试题描述 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...
- Ugly Numbers
Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21918 Accepted: 9788 Descrip ...
随机推荐
- 检测zookeeper和kafka是否正常
cd $(dirname $) source ~/.bash_profile count_zoo=`ps -ef | grep "config/zookeeper.properties&qu ...
- mysql显示乱码问题
在select * from table:时往往会出现上图所示乱码现象 此时,输入status,会发现: 此时只要SET NAMES utf8即可解决该问题.此时,再次输入status: 总结:S ...
- 学习总结 java 异常
package com.hanqi.ec; public class Test1 { public static void main(String[] args) { int a = 10 , b = ...
- Windows10系统如何安装Microsoft Visual Studio 2015及最小子数组和求解
一.Windows10系统如何安装Microsoft Visual Studio 2015. 1.首先到Visual Studio官方网站(https://www.visualstudio.com/v ...
- Python 编程规范-----转载
Python编程规范及性能优化 Ptyhon编程规范 编码 所有的 Python 脚本文件都应在文件头标上 # -*- coding:utf-8 -*- .设置编辑器,默认保存为 utf-8 格式. ...
- Does FTK index search support regular expression?
Some of my friends ask me a question: "Does FTK index search support regular expression?" ...
- EnCase v7 could not recognize Chinese character folder names / file names on Linux Platform
Last week my friend brought me an evidence file duplicated from a Linux server, which distribution i ...
- .NET中的属性
1.What?什么是属性 属性是对字段的封装.当类中有了一个字段以后,为了控制这个字段对外的一些表现(例如可访问性,是只读?只写?或者对自读赋值做一些必要的验证等等)我们把这个字段私有化( ...
- 实例分析ELF文件静态链接
参考文献: <ELF V1.2> <程序员的自我修养---链接.装载与库>第4章 静态链接 开发平台: [thm@tanghuimin static_link]$ uname ...
- [系统]制作老毛桃U盘WinPE
准备工作,1G以上的U盘一个, Winpe 工具一个,个人推荐老毛桃winpe Ghost镜像文件(这个不用说了吧,能想到U盘装系统肯定都知道的) 可以开始了:插入U盘(最好把U盘里的东西清空,自己保 ...