http://acm.hdu.edu.cn/showproblem.php?pid=1058

Problem Description
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.

Write a program to find and print the nth element in this sequence

 
Input
The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n.
 
Output
For each test case, print one line saying "The nth humble number is number.". Depending on the value of n, the correct suffix "st", "nd", "rd", or "th" for the ordinal number nth has to be used like it is shown in the sample output.
 
Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
 
Sample Output
The 1st humble number is 1.
The 2nd humble number is 2.
The 3rd humble number is 3.
The 4th humble number is 4.
The 11th humble number is 12.
The 12th humble number is 14.
The 13th humble number is 15.
The 21st humble number is 28.
The 22nd humble number is 30.
The 23rd humble number is 32.
The 100th humble number is 450.
The 1000th humble number is 385875.
The 5842nd humble number is 2000000000.
 
状态转移方程:F(n)=min(f(i)*2, f(j)*3, f(k)*5, f(m)*7); n<(i,j,k,m)
注意:11th , 12th, 13th.
 
 #include <stdio.h>

 int min(int a, int b)
{
if(a>b)
return b;
else
return a;
} int min4(int a, int b, int c, int d)
{
return min(min(a,b), min(c,d));
} const int N=;
int F[N]; int main()
{ int n=;
F[]=; int h2, h3, h5, h7;
h2=h3=h5=h7=; while(F[n]<)
{
F[++n]=min4(*F[h2], *F[h3], *F[h5], *F[h7]);
if(F[n]==*F[h2]) h2++;
if(F[n]==*F[h3]) h3++;
if(F[n]==*F[h5]) h5++;
if(F[n]==*F[h7]) h7++;
} while(scanf("%d", &n)!=EOF)
{
if(n==) break;
if(n%== && n%!=)
printf("The %dst humble number is %d.\n", n, F[n]);
else if(n%== && n%!=)
printf("The %dnd humble number is %d.\n", n, F[n]);
else if(n%== && n%!=)
printf("The %drd humble number is %d.\n", n, F[n]);
else
printf("The %dth humble number is %d.\n", n, F[n]);
} return ;
}

hdu-题目:1058 Humble Numbes的更多相关文章

  1. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  2. 九度oj 题目1058:反序输出

    题目1058:反序输出 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:9677 解决:3495 题目描述: 输入任意4个字符(如:abcd), 并按反序输出(如:dcba) 输入: 题目可 ...

  3. HDU 1058 Humble Numbers(离线打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...

  4. HDU 1058 Humble Number

    Humble Number Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humbl ...

  5. HDU 1058 Humble Numbers (动规+寻找丑数问题)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  6. hdu 1058 Humble Numbers

    这题应该是用dp来做的吧,但一时不想思考了,写了个很暴力的,类似模拟打表,然后排序即可,要注意的是输出的格式,在这里wa了一发,看了别人的代码才知道哪些情况没考虑到. #include<cstd ...

  7. HDU 1058 Humble Numbers【DP】

    题意:给出丑数的定义,只含有2,3,5,7这四个素数因子的数称为素数.求第n个丑数. 可以先观察几个丑数得出规律 1:dp[1] 2:min(1*2,1*3,1*5,1*7) 3:min(2*2,1* ...

  8. HDU 1058 Humble Numbers (DP)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. hdu 1058:Humble Numbers(动态规划 DP)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. 20155213 2016-2017-2 《Java程序设计》第一周学习总结

    20155213 2016-2017-2 <Java程序设计>第一周学习总结 教材学习内容总结 了解JVM.JRE与JDK,并下载.安装.测试JDK JVM JVM是Java Virtua ...

  2. Java程序设计 第16周 课堂实践

    Java程序设计 第16周 课堂实践 -- 数据库2 课堂实践任务2 查询world数据库,获得人口超过500万的所有城市的列表. 代码分析 实现查询数据库需要我们修改Message.java,Mes ...

  3. 20155330 实验二 Java面向对象程序设计

    20155330 实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步 ...

  4. L015-linux系统文件权限体系手把手详解小结

    L015-linux系统文件权限体系手把手详解小结 2016-5-24 今天星期二,昨天和今天利用一些闲散时间把第15节课学完了,最近有点懒散哈,还得努力才是.. 这节课内容不多,扩展的也少,主要就是 ...

  5. 宿主机 PL/SQL Developer 连接虚拟机 ORACLE 数据库

    1.确保主机与虚拟机间通信正常,双方关闭window防火墙.如能 ping 通,请确保两机IP在一个网段 2.主机安装orcl客户端 3.虚拟机 D:\app\lin\product\11.2.0\d ...

  6. Qt 将字符串转成16进制显示

    最近项目用到了需要将字符串转换成16进制显示.这玩意折腾了一上午. 首先,数据块内容 struct UserData { char Head[3] = {'X','J','J'}; char Flag ...

  7. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) E. Down or Right

    从(1,1,n,n)每次只变一个坐标,进行询问. 如果问到对角线有距离限制, 再从(1,1,n/2,n/2)询问到(n/2,n/2,n,n) 记住前半部分贪心忘上走,后本部分贪心往右走 因为最后的路线 ...

  8. spark重点知识

    1 scala 2 spark rdd 3 sprak core 4 性能优化 5 spark sql 6 spark streaming 掌握程度-精通的理解:

  9. 数据库sql优化总结之1-百万级数据库优化方案+案例分析

    项目背景 有三张百万级数据表 知识点表(ex_subject_point)9,316条数据 试题表(ex_question_junior)2,159,519条数据 有45个字段 知识点试题关系表(ex ...

  10. MAC清理DS_Store和._文件

    打开终端输入 find . -name .DS_Store -type f -delete ; find . -type d | xargs dot_clean