hdoj-1058(优先队列)---priority_queue====丑数

来源:互联网 发布:淘宝网页浏览需要登录 编辑:程序博客网 时间:2024/05/21 18:05
#include<iostream>#include<cstring>#include<vector>#include<queue>#include<set>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 6000;LL sv[maxn];priority_queue<LL, vector<LL>,  greater<LL> > Q; //数值越小的优先级越高 set<LL> S;void pre() {S.clear();int c[4] = {2, 3, 5, 7};Q.push(1);S.insert(1);int cnt = 1;while(!Q.empty()) {LL temp = Q.top();Q.pop();sv[cnt++] = temp;LL tn;//cout << sv[cnt-1] << endl;for(int i = 0; i < 4; i++) {tn = c[i]*temp;if(!S.count(tn)) {S.insert(tn);Q.push(tn);}}if(cnt == 5850) break;} }void _print(int num) {LL n = num;if(n%10==1&&n%100!=11)              printf("The %dst humble number is %lld.\n",n,sv[n]);          else if(n%10==2&&n%100!=12)              printf("The %dnd humble number is %lld.\n",n,sv[n]);          else if(n%10==3&&n%100!=13)              printf("The %drd humble number is %lld.\n",n,sv[n]);          else              printf("The %dth humble number is %lld.\n",n,sv[n]); } int main() {int N;pre();while(cin >> N && N) {_print(N);}return 0;} 


序数词的问题真心是被搞得头痛。。。。


以1、2、3结尾的(但是其中不包括


以11、12、13结尾的)都用st、nd、rd,


 其他的都用th。



0 0