您的位置:首页 > 产品设计 > UI/UE

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

2016-03-05 15:45 459 查看
#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
);
else if(n%10==2&&n%100!=12)
printf("The %dnd humble number is %lld.\n",n,sv
);
else if(n%10==3&&n%100!=13)
printf("The %drd humble number is %lld.\n",n,sv
);
else
printf("The %dth humble number is %lld.\n",n,sv
);
}
int main() {
int N;
pre();
while(cin >> N && N) {
_print(N);
}
return 0;
}


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

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





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

其他的都用th。







内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: