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. java课堂实践(5月17日)20155317 王新玮

    对P145 MathTool.java 代码托管 在IDEA中,使用JUnit进行单元测试,测试用例不少于三个,要包含正常情况,边界情况.提交测试代码和运行结果截图,加上学号水印,提交码云代码链接. ...

  2. 20155327 2016-2017-2 《Java程序设计》第10周学习总结

    20155327 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 Java的网络编程 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. ...

  3. 20155337 2016-2017-2 《Java程序设计》第三周学习总结

    20155337 2016-2017-2 <Java程序设计>第死周学习总结 教材学习内容总结 第六章 •何谓继承: 面向对象中,为避免多个类间重复定义共同行为.(简单说就是将相同的程序代 ...

  4. 【BZOJ4553】[HAOI2016&TJOI2016]序列

    [BZOJ4553][HAOI2016&TJOI2016]序列 题面 bzoj 洛谷 题解 一定要仔细看题啊qwq... 我们设$mn[i],mx[i]$表示第$i$个位置上最小出现.最大出现 ...

  5. Drupal views中实现两列布局

    Views中的format有table,grid,unformatted list等,但是没有2 columns等选项. 如果要达到如下效果: 左侧一列有title,content,右侧一列image ...

  6. C# 多线程的等待所有线程结束的一个问题

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  7. katalon系列十六:代码运行时实时创建元素对象或列表

    Katalon的常规方法是先抓取元素并保存到仓库,在脚本中需要用到的时候调取,但假如元素属性和个数是可变的,就不能事先保存到仓库了,需要在脚本运行时实时创建. 代码运行时实时创建一个元素对象的例子im ...

  8. git remote add origin错误

    如果输入$ Git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git 提示出错信息:fatal: remote ...

  9. 每天一个linux命令集

    linux命令汇总,装载来自: http://www.cnblogs.com/peida/category/309012.html

  10. windows64系统下安装 redis服务 (详细)

    Linux下Redis安装链接 :     转到 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表) ...