hdu 1058 Humble Number

题目链接:

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

解题思路:

orz英语序数。。。

first 第一   second 第二   third 第三   fourth 第四   fifth 第五   sixth 第六   seventh 第七   eighth 第八   ninth 第九   tenth 第十   eleventh 第十一   twelfth 第十二   thirteenth 第十三   fourteenth 第十四   fifteenth 第十五   sixteenth 第十六   seventeenth 第十七   eighteenth 第十八   nineteenth 第十九   twentieth 第二十   twenty-first 第二十一   twenty-second 第二十二   twenty-third 第二十三   

剩下的直接求丑数就行了。。。

AC代码:

#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,int> node_type;
ll result[6000];

int main(){
    priority_queue<node_type,vector<node_type>,greater<node_type> > q;
    q.push(make_pair(1,2));
    for(int i = 1; i <= 5842; i++){
        node_type node  = q.top();
        q.pop();
        switch(node.second){
        case 2: q.push(make_pair(node.first*2,2));
        case 3: q.push(make_pair(node.first*3,3));
        case 5: q.push(make_pair(node.first*5,5));
        case 7: q.push(make_pair(node.first*7,7));
        }
        result[i] = node.first;
    }
    int n;
    while(scanf("%d",&n) && n){
        int tmp = n%10;
        if(tmp == 1 && (n % 100 != 11))
            printf("The %dst humble number is ",n);
        else if(tmp == 2 && (n % 100 != 12))
            printf("The %dnd humble number is ",n);
        else if(tmp == 3 && (n % 100 != 13))
            printf("The %drd humble number is ",n);
        else
            printf("The %dth humble number is ",n);
        printf("%lld.\n",result[n]);//手残,wrong到哭,原因是没有加句号。。。
    }
    return 0;
}


你可能感兴趣的:(丑数)