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。
相关文章推荐
- HDU 4126 Genghis Khan the Conqueror(最小生成树)
- iOS之UIScrollView常用属性和用法总结
- DataBase -- Employees Earning More Than Their Managers My Submissions Question
- kidd风的IOS日志之UICollectionView之介绍使用篇
- 系统默认的刷新方法(UIRefreshControl)
- N1:Stack Queue DFS BFS
- 让UITableViewCell的分隔线宽度等于屏幕的宽度
- UESTC 758 P酱的冒险旅途
- openstack-glance-api.service start request repeated too quickly, refusing to start
- HDU 1297 Children’s Queue 递归+大数
- iOS UIActionSheet提示框
- ugui 中有关grid layout group的适配问题
- UVA 10689 Yet another Number Sequence(矩阵快速幂求Fib数列)
- UVA 10689 Yet another Number Sequence(矩阵快速幂求Fib数列)
- UITapGestureRecognizer 的使用,判断点击哪个控件
- QuickSort 快排算法 java
- require笔札
- Handler中的四种更新UI写法
- poj--3061--Subsequence(贪心)
- poj--3061--Subsequence(贪心)