题意

PDF

分析

用堆和集合维护即可。

时间复杂度\(O(1500 \log n)\)

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
    rg T data=0;
    rg int w=1;
    rg char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        data=data*10+ch-'0';
        ch=getchar();
    }
    return data*w;
}
template<class T>T read(T&x)
{
    return x=read<T>();
}
using namespace std;
typedef long long ll;

co int coef[3]={2,3,5};

int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    priority_queue< ll,vector <ll> ,greater <ll> > pq;
    set <ll> s;
    pq.push(1);
    s.insert(1);
    for(int i=1;;++i)
    {
        ll x=pq.top();
        pq.pop();
        if(i==1500)
        {
            cout<<"The 1500'th ugly number is "<<x<<".\n";
            break;
        }
        for(int j=0;j<3;++j)
        {
            ll y=x*coef[j];
            if(!s.count(y))
            {
                s.insert(y);
                pq.push(y);
            }
        }
    }
    return 0;
}

UVA136 Ugly Numbers的更多相关文章

  1. UVa136 Ugly Numbers(优先队列priority_queue)

    Ugly Numbers 题目 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, ...

  2. UVA136 Ugly Numbers【set】【优先队列】

    丑数 丑数是指不能被2,3,5以外的其他素数整除的数.把丑数从小到大排列起来,结果如下: 1,2,3,4,5,6,8,9,10,12,15,… 求第1500个丑数. 提示:从小到大生成各个丑数.最小的 ...

  3. 【UVA - 136】Ugly Numbers(set)

    Ugly Numbers Descriptions: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...

  4. [POJ1338]Ugly Numbers

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

  5. Ugly Numbers

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

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

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

  7. leetcode@ [263/264] Ugly Numbers & Ugly Number II

    https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...

  8. Geeks Interview Question: Ugly Numbers

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...

  9. 136 - Ugly Numbers

     Ugly Numbers  Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3 ...

随机推荐

  1. mysql 5.6 设置root初始密码正确步骤,避免入坑

    http://blog.csdn.net/lw_power/article/details/47368167

  2. 批处理文件 bat 的入门命令

    1. echo on和echo off echo on表示打开回显,echo off表示关闭回显,何为回显?打开回显就是执行命令时会把命令显示出来,关闭回显反之. 2.echo [message] 这 ...

  3. 使用axis2构建webservice

    axis2是可以实现webservice的一个插件,使用这个插件可以发布webservice 1:可以使用这个插件来发布webservice,可以看网址:http://clq9761.iteye.co ...

  4. C++ dll的隐式与显式调用

    应用程序使用DLL可以采用两种方式:一种是隐式链接,另一种是显式链接.在使用DLL之前首先要知道DLL中函数的结构信息.Visual C++6.0(或者更先进的版本)在VC\bin目录下提供了一个名为 ...

  5. cmake手册

    cmake手册 部分转载自:http://www.cnblogs.com/coderfenghc/tag/cmake/ CMake2.8.3 主索引 命令名称 用法 描述 命令选项 生成器 命令 属性 ...

  6. oracle数据库插入优化

    通过程序要把1000万的数据插入到数据表中,刚开始每100条数据耗时50ms左右,但是越往后越慢,最慢到了十几秒的都有,真实好坑了. 于是在网上百度了一波,如何进行insert优化.倒是有了一点小小的 ...

  7. 使用springmvc时报错JSPs only permit GET POST or HEAD

    两个地方需要注意:第一处在web.xml文件中不要忘记配置 <filter> <filter-name>HiddenHttpMethodFilter</filter-na ...

  8. ctci1.1

    )         ;     ; i < len; i++){         if(place.find(str[i]) == place.end())             place. ...

  9. mysql数据库(三):查询的其他用法

    一. 查询—IN的用法 语法:select ... from 表名 where 字段 a in (值b, 值c, 值d...) 等价于 select ... from 表名 where 字段a=值b ...

  10. Spring 依赖注入(一、注入方式)

    Spring是一个依赖注入(控制反转)的框架,那么依赖注入(标控制反转)表现在那些地方了? 即:一个类中的属性(其他对象)不再需要手动new或者通过工厂方法进行创建,而是Spring容器在属性被使用的 ...