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. Hadoop HA高可用集群搭建(2.7.2)

    1.集群规划: 主机名        IP                安装的软件                            执行的进程 drguo1  192.168.80.149 j ...

  2. 20155222 2016-2017-2 《Java程序设计》实验二

    1 测试 public class MyUtil{ public static String percentage2fivegrade(int grade){ //如果成绩小于60,转成"不 ...

  3. 关于正则表达式"\b"

    今天刚刚开始看正则表达式就遇到一个十分头疼的问题,原文是这样的: “不幸的是,很多单词里包含hi这两个连续的字符,比如him,history,high等等.用hi来查找的话,这里边的hi也会被找出来. ...

  4. sql语句-3-聚合数据查询

  5. Linux 下 的 Oracle,如何安装 tnsname

    运行 netca 即可:

  6. c++ 创建单项链表

    建立单向链表 头指针Head 插入结点 //建立头结点 Head Head=p= malloc(sizeof( struct stu_data)); // memset(stu,,sizeof( st ...

  7. python 多线程笔记(2)-- 锁

    锁是什么?什么场合使用锁? 锁是一种机制,用于保护那些会引起冲突的资源. 比如上厕所,进去之后第一件事干嘛?把厕所门反锁!表示什么呢?表示这个厕所正在使用中! 至于在厕所里面干大事.干小事.还是打飞机 ...

  8. Entity Framework for Oracle 基本配置

    1.需要安装ODAC 如果不安装ODAC,在数据源连接的配置中,看不到Oracle的选项 我下载安装的组件是32-bit Oracle Data Access Components (ODAC)  w ...

  9. 【第七章】MySQL数据库备份-物理备份

    一.数据库备份 备份的目的: 备份: 能够防止由于机械故障以及人为误操作带来的数据丢失,例如将数据库文件保存在了其它地方. 冗余: 数据有多份冗余,但不等备份,只能防止机械故障还来的数据丢失,例如主备 ...

  10. sendcloud golang 发送短信 示例代码

    package main import ( "fmt" "crypto/md5" "encoding/hex" "sort&quo ...