hdu 1058 Humble Numbers
来源:互联网 发布:java自行车是高端的吗 编辑:程序博客网 时间:2024/05/29 00:29
由于数字达到了2亿,所以用不了筛选,我用的是bfs+map判重
至于输出格式.......看代码吧~
#include<iostream>#include<cstdio>#include<queue>#include<map>#include<algorithm>#include<cstring>#define maxn 2000000000+5#define ll long longusing namespace std;int f[6000];priority_queue<ll, vector<ll>, greater<ll> >mapp;map<ll,int>root;void solve(){ll x=1;mapp.push(x);int k=0;while(mapp.size()){x=mapp.top();mapp.pop();f[k++]=x;if(x*2<maxn&&root.find(x*2)==root.end()) mapp.push(2*x),root[2*x]=1;if(x*3<maxn&&root.find(x*3)==root.end()) mapp.push(3*x),root[3*x]=1;if(x*5<maxn&&root.find(x*5)==root.end()) mapp.push(5*x),root[5*x]=1;if(x*7<maxn&&root.find(x*7)==root.end()) mapp.push(7*x),root[7*x]=1;} }int main(){solve();int m;while(scanf("%d",&m)!=EOF&&m){if(m%10==1 && m%100!=11) printf("The %dst humble number is %d.\n",m,f[m-1]); else if(m%10==2 && m%100!=12) printf("The %dnd humble number is %d.\n",m,f[m-1]); else if(m%10==3 && m%100!=13) printf("The %drd humble number is %d.\n",m,f[m-1]); else printf("The %dth humble number is %d.\n",m,f[m-1]);}return 0;}
0 0
- HDU 1058 Humble Numbers
- hdu 1058 Humble Numbers
- hdu 1058 Humble Numbers
- HDU 1058 Humble Numbers
- hdu 1058 Humble Numbers
- HDU 1058 Humble Numbers
- hdu 1058 humble numbers
- hdu 1058 Humble Numbers
- hdu 1058 Humble Numbers
- HDU 1058 Humble Numbers
- HDU 1058 Humble Numbers
- HDU 1058 Humble Numbers
- hdu 1058 Humble Numbers
- HDU-1058 Humble Numbers
- hdu 1058 Humble Numbers
- HDU 1058 Humble Numbers
- HDU 1058 Humble Numbers
- hdu 1058 Humble Numbers
- 我们能用HTML5 Canvas做什么
- Win7下安装Hadoop
- HashMap 与 ConcurrentHashMap
- “利润定乾坤”的商业模式陷阱将令你的企业自掘坟墓
- 详解CSS的继承性及其利用
- hdu 1058 Humble Numbers
- css3文字霓虹灯光效果
- 在WebView加载页面时添加cookies
- [Unity实战]框选效果
- Longest Common Prefix
- 【JavaScript】复选框的全选、反选,判断哪些复选框被选中
- VC如何改变编辑框的背景颜色方法
- 程序员的量化交易之路(29)--Cointrader之Tick实体(16)
- linux-进程监控