题目

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

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.

题解

原题,具体看>HDU 1069.Monkey and Banana<

代码

/*
By:OhYee
Github:OhYee
Blog:http://www.oyohyee.com/
Email:oyohyee@oyohyee.com

かしこいかわいい?
エリーチカ!
要写出来Хорошо的代码哦~
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
using namespace std;

const int maxn = 35;

int kase = 0;
struct Node {
    int x,y,h;
    Node(int x = 0,int y = 0,int h = 0) {
        this->x = min(x,y);
        this->y = max(x,y);
        this->h = h;
    }
    bool operator < (const Node &rhs)const {
        if(x == rhs.x)
            return y < rhs.y;
        else
            return x < rhs.x;
    }
    static bool cmp(Node &a,Node &b) {
        return (a.x < b.x && a.y < b.y);
    }
};
Node S[3 * maxn];
int dp[3 * maxn];

bool  Do() {
    int n;
    scanf("%d",&n);
    if(n == 0)
        return false;

    printf("Case %d: maximum height = ",++kase);

    for(int i = 0;i < n;i++) {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        S[i * 3 + 1] = Node(x,y,z);
        S[i * 3 + 2] = Node(y,z,x);
        S[i * 3 + 3] = Node(z,x,y);
    }

    sort(S,S + 3 * n + 1);

    int Max = 0;

    for(int i = 1;i <= 3 * n;i++) {
        dp[i] = 0;
        for(int j = 0;j < i;j++) {
            if(Node::cmp(S[j],S[i])) {
                dp[i] = max(dp[i],dp[j] + S[i].h);
            }
        }
        Max = max(Max,dp[i]);
    }

    printf("%d\n",Max);
    return true;
}

int main() {
    while(Do());
    return 0;
}