hdoj1058_Humble Numbers(dp)

来源:互联网 发布:淘宝上怎么买正品 编辑:程序博客网 时间:2024/06/06 21:38

思路:4个游标打表

#include<iostream>#include<string.h>#include<vector>#include<algorithm>using namespace std;unsigned long long table[5843];void gettable(){    int a = 1, b = 1, c = 1, d = 1;    table[1] = 1;    for (int i = 2; i <= 5842; i++)    {        unsigned long long ta = table[a] * 2;        unsigned long long tb = table[b] * 3;        unsigned long long tc = table[c] * 5;        unsigned long long td = table[d] * 7;        unsigned long long temp = min(min(ta,tb), min(tc,td));        table[i] = temp;        if (ta == temp)            a++;        if (tb == temp)            b++;        if (tc == temp)            c++;        if (td == temp)            d++;    }}int main(){    gettable();    int n;    while (cin >> n&&n)    {        cout << "The " << n;        if (n % 100 == 11 || n % 100 == 12||n%100==13)            cout << "th";        else if (n % 10 == 1)            cout << "st";        else if (n % 10 == 2)            cout << "nd";        else if (n % 10 == 3)            cout << "rd";        else            cout << "th";        cout << " humble number is " << table[n] << "." << endl;    }    return 0;}
0 0