HDOJ 1508 Humble Numbers

题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1058


Humble Numbers
丑数~~~
汗,不知道为何叫这个名字,挺搞笑的。

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
// Author: Tanky Woo
// HDOJ 1058
#include <iostream>
using namespace std;
 
__int64 humble[6000];
int _min(int a, int b, int c, int d)
{
    int m;
    if(a < b)
        m = a;
    else
        m = b;
    if(m > c)
        m = c;
    if(m > d)
        m = d;
    return m;
}
 
int main()
{
    int e1=1, e2=1, e3=1, e4=1;
    __int64 a1, a2, a3, a4;
    humble[1] = 1;
    for(int i=2; i<6000; ++i)
    {
        a1 = 2*humble[e1];
        a2 = 3*humble[e2];
        a3 = 5*humble[e3];
        a4 = 7*humble[e4];
        humble[i] =  _min(a1, a2, a3, a4);
        if(humble[i] == a1)
            e1++;
        if(humble[i] == a2)
            e2++;
        if(humble[i] == a3)
            e3++;
        if(humble[i] == a4)
            e4++;
    }
 
    int n;
    while(scanf("%d", &n) && n)
    {
        if(n%100==11 || n%100==12 || n%100==13)
            printf("The %dth humble number is %d.\n", n, humble[n]);
        else if(n % 10 == 1)
            printf("The %dst humble number is %d.\n", n, humble[n]);
        else if(n % 10 == 2)
            printf("The %dnd humble number is %d.\n", n, humble[n]);
        else if(n % 10 == 3)
            printf("The %drd humble number is %d.\n", n, humble[n]);
        else
            printf("The %dth humble number is %d.\n", n, humble[n]);
    }
    return 0;
}

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

发表评论

电子邮件地址不会被公开。 必填项已用*标注