码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1058 Humble Numbers

时间:2017-05-21 19:39:47      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:筛选   can   vector   space   stream   pop   pac   art   ==   

因为数字达到了2亿。所以用不了筛选。我用的是bfs+map判重

至于输出格式.......看代码吧~

#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#define maxn 2000000000+5
#define ll long long
using 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;
}


 

hdu 1058 Humble Numbers

标签:筛选   can   vector   space   stream   pop   pac   art   ==   

原文地址:http://www.cnblogs.com/blfbuaa/p/6885559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!