本来应当是一道优先队列或者堆的题 因为每个数都应该是已经得到的数*2 *3 *5 *7而得到的 但是 2*7 大于 3*2 这就必须保证每次取得都是没有拿过的最小的数

但是它主动降低难度在样例里卖了个萌 n的范围是1~5842 而第5842在样例里给出了..所以我们在取出一个数 求出它的*2 *3 *5 *7的时候做一下判断 如果大于最后一位就直接break 因为相乘的顺序在 可以省一点时间

在判断某个数是否出现过的时候 开不出那么大的vis数组 所以直接for循环从ans数组中寻找 所幸没有超时QAQ

尤其需要注意的是题目的思考并不难 但是输出的英语用法是坑

1 2 3 分别是 first second third 所以缩写的是 st nd rd

21 22 23 等 是 twenty - first twenty - second twenty- third 等 它们的缩写都是 st nd rd

但是11 12 13 不是.. 它们的第次缩写都是 th

(我的输出代码写得判断很麻烦..因为我懒得改..)

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
#include<queue>
#include<iostream>
using namespace std;
long long int e[6050];
int w;
bool find(long long int x)
{
for(int i=0;i<w;i++)
{
if(e[i]==x)
return true;
}
return false;
}
void init()
{
w=0;
queue<long long int >q;
q.push(2);
q.push(3);
q.push(5);
q.push(7);
e[w++]=1;
e[w++]=2;e[w++]=3;e[w++]=5;e[w++]=7;
while(!q.empty())
{
long long int z=q.front();q.pop();
/* if(w==5842)
return ;*/
for(int i=0;i<4;i++)
{
long long int x=z;
///if(x> 2000000000)continue;
if(i==0)
{
x*=2;
if(x> 2000000000)
break;
if(!find(x))
{
e[w++]=x;
q.push(x);
}
}
else if(i==1)
{
x*=3;
if(x> 2000000000)
break;
if(!find(x))
{
e[w++]=x;
q.push(x);
}
}
else if(i==2)
{
x*=5;
if(x> 2000000000)
break;
if(!find(x))
{
e[w++]=x;
q.push(x);
}
}
else if(i==3)
{
x*=7;
if(x> 2000000000)
break;
if(!find(x))
{
e[w++]=x;
q.push(x);
}
} }
} }
int main(){
init();
int n;
sort(e,e+w);
while(~scanf("%d",&n))
{
if(n==0)
break;
if(n==11)
printf("The 11th humble number is ");
else if(n==12)
printf("The 12th humble number is ");
else if(n==13)
printf("The 13th humble number is ");
else
{
if(n%10!=1&&n%10!=2&&n%10!=3)
{
printf("The %dth humble number is ",n);
}
else if(n%10==1&&n%100!=11)
{
printf("The %dst humble number is ",n);
}
else if(n%10==2&&n%100!=12)
{
printf("The %dnd humble number is ",n);
}
else if(n%10==3&&n%100!=13)
{
printf("The %drd humble number is ",n);
}
else
printf("The %dth humble number is ",n);
}
printf("%I64d.\n",e[n-1]);
}
}

  

最新文章

  1. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(24)-权限组的设计和实现(附源码)(终结)
  2. TopFreeTheme精选免费模板【20130701.特别版】
  3. BeanDefinition的Resource定位——3
  4. tomcat之JNDI数据源配置
  5. MySQL协议分析
  6. Linux Shell编程(5)——shell特殊字符(下)
  7. linux Bash bug修复记录
  8. WebView.destroy() called while still attached 的解决的方法
  9. boost之program_options库,解析命令行参数、读取配置文件
  10. Linq 实现sql中的not in和in条件查询
  11. linux的软件安装方式总结
  12. bootstrap概述
  13. Http状态信息
  14. ElasticSearch6.5.0 【安装IK分词器】
  15. SQL Server 性能优化实战系列(一)
  16. 7.15python进程锁
  17. Asp.net core 学习笔记 ( OData )
  18. java Random.nextInt()方法
  19. python with 语句妙用
  20. 如何修改路由器的登录IP地址?

热门文章

  1. linux 远程 windows 命令:rdesktop vs windows mstsc
  2. 第六步:Lucene查询索引
  3. Android中JNI 的一些常用Method说明
  4. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem G: Check The Check(模拟国际象棋)
  5. PowerDesigner破解
  6. hdu 4578 线段树 ****
  7. linux下动态库so文件的一些认识
  8. UVALive 6887 Book Club 最大流解最大匹配
  9. CodeForces 300C --数论
  10. Spring的类型转换器