hdu 1058_优先队列

来源:互联网 发布:js读取本地txt文件 编辑:程序博客网 时间:2024/05/16 08:24

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

#include <queue>#include <map>#include <iostream>#include <functional>using namespace std;#define MAXI 5843priority_queue<__int64, vector<__int64>, greater<__int64> > Q;__int64 hn[MAXI], l;map<__int64, bool> exi;void init(){    __int64 tmp;    l = 1;    Q.push(1);    while (l < MAXI)    {        tmp = Q.top();        Q.pop();        if (exi[tmp]) continue;        exi[tmp] = 1;        hn[l++] = tmp;        Q.push(tmp * 2);        Q.push(tmp * 3);        Q.push(tmp * 5);        Q.push(tmp * 7);    }}int main(){    int n;    init();    while (scanf("%d", &n), n)     {        printf("The %d", n);        if (n % 10 == 1 && n % 100 != 11) printf("st ");        else if (n % 10 == 2 && n % 100 != 12) printf("nd ");        else if (n % 10 == 3 && n % 100 != 13) printf("rd ");        else printf("th ");        printf("humble number is %I64d.\n", hn[n]);    }    return 0;}


0 0
原创粉丝点击