HDU 1058

我用优先级队列做的,需要打表不然会超时。

注意:1200也是rd所以判断条件应该为n%100!=…

/*Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
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.*/
#include<iostream>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
int a[]= {2,3,5,7};
    ll h[6000];
int main()
{


    int n;

    set<ll> s;
    priority_queue<ll,vector<ll>,greater<ll> > pq;
    pq.push(1);
    s.insert(1);
    ll t;
    for(int i=1;i<=5842; i++)
    {
        t=pq.top();
        h[i]=t;
        pq.pop();
        for(int j=0; j<4; j++)
        {
            if(!s.count(t*a[j]))
            {
                s.insert(t*a[j]);
                pq.push(t*a[j]);
            }
        }
    }
    while(cin>>n&&n)
    {
        if(n%10==2&&n%100!=12)
        {
            cout<<"The "<<n<<"nd"<<" humble number is "<<h[n]<<"."<<endl;
        }
        else if(n%10==1&&n%100!=11)
        {
            cout<<"The "<<n<<"st"<<" humble number is "<<h[n]<<"."<<endl;
        }
        else if(n%10==3&&n%100!=13)
        {
            cout<<"The "<<n<<"rd"<<" humble number is "<<h[n]<<"."<<endl;
        }
        else
        {
            cout<<"The "<<n<<"th"<<" humble number is "<<h[n]<<"."<<endl;
        }
    }
return 0;
}

转载于:https://www.cnblogs.com/dillydally/p/9567829.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值