题目大意:只有素因子2,3,5的数叫做丑数。输出第1500个丑数即可。

  这个...好吧,直接输出就是了。自己写一个小程序先计算一下,这就是黑盒测试的好处啊,“我们的目标是解决问题,而不是为了写程序而写程序,同时应该保持简单(Kepp It Simple and Stupid, KISS)”,摘自《算法竞赛入门经典》。

 #include <cstdio>

 int main()
{
int p = ; // the number of ugly number
int i;
for (i = ; ; i++)
{
int t = i;
while (t % == ) t /= ;
while (t % == ) t /= ;
while (t % == ) t /= ;
if (t == )
{
p++;
//printf("%d is the %dth ugly number\n", i, p);
}
if (p >= ) break;
}
printf("%d\n", i);
return ;
}

  这个是暴力枚举测试的,简单直接,不过效率不高,还看到一个用dp解决的,以后在完善啦


  忽然想试一下这道题c和c++的差别,就换了一下头文件用c提交,竟然用了12ms,c++才用了9ms,为什么会这样呢?c不是应该比c++快的吗?        2013.7.16

UVa 136 - Ugly Numbers的更多相关文章

  1. UVA.136 Ugly Numbers (优先队列)

    UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...

  2. UVA - 136 Ugly Numbers (有关set使用的一道题)

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

  3. UVA - 136 Ugly Numbers(丑数,STL优先队列+set)

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

  4. UVa 136 Ugly Numbers【优先队列】

    题意:给出丑数的定义,不能被除2,3,5以外的素数整除的的数称为丑数. 和杭电的那一题丑数一样--这里学的紫书上的用优先队列来做. 用已知的丑数去生成新的丑数,利用优先队列的能够每次取出当前最小的丑数 ...

  5. 136 - Ugly Numbers

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

  6. 136 Ugly Numbers(priority_queue+逆向求解要求数)

    题目链接: https://cn.vjudge.net/problem/UVA-136 /*问题 输出第1500个丑数,丑数的定义是不能被2,3,5以外的其他素数整除的数 解题思路 直接硬暴力先试一下 ...

  7. 丑数(Ugly Numbers, UVa 136)

    丑数(Ugly Numbers, UVa 136) 题目描述 我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因 ...

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

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

  9. Ugly Numbers UVA - 136(优先队列+vector)

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

随机推荐

  1. cordova插件开发-1

    这是初级编,实现了js调用Android代码 首先需要编写java代码: public class AppUpdate extends CordovaPlugin { @Override public ...

  2. JS跨域代码

    //部分JS代码 $.ajax({ async: false, url: "http://www.xxxx.com/api/", type: "GET",//不 ...

  3. 判断非法字符串的类方法,与jsp

    private String_do_judge judge; if (judge.isContain(key)) { return "feifa"; } 上面这写代码添加到进入ac ...

  4. RocketMQ源码 — 三、 Producer消息发送过程

    Producer 消息发送 producer start producer启动过程如下图 public void start(final boolean startFactory) throws MQ ...

  5. HDU 2485 Destroying the bus stations

    2015 ACM / ICPC 北京站 热身赛 C题 #include<cstdio> #include<cstring> #include<cmath> #inc ...

  6. Struts2--默认Action

    何时使用:  访问的网页不存在, 显示错误页面, 或者显示主页. 有时存在一种情况, 就是找不到对应action 可以在struts.xml里设置一个默认的action <?xml versio ...

  7. Struts2--中文问题

    有中文的情况下, form method都要用post: 如果jsp输入中文返回到后台action输出时会显示乱码, struts.xml已经设置 <constant name="st ...

  8. javascript 中的闭包

    在 javascript 中,函数可以当做参数传递,也可以当做返回值返回. 当一个函数内部返回值为一个函数时, 就形成了闭包.(闭包里面的 this 问题) 如下面代码 Function.protot ...

  9. POJ 3186 Treats for the Cows

    简单DP dp[i][j]表示的是i到j这段区间获得的a[i]*(j-i)+... ...+a[j-1]*(n-1)+a[j]*n最大值 那么[i,j]这个区间的最大值肯定是由[i+1,j]与[i,j ...

  10. AsParallel 用法

    http://www.cnblogs.com/leslies2/archive/2012/02/08/2320914.html AsParallel 通常想要实现并行查询,只需向数据源添加 AsPar ...