题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1058

Humble Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29253    Accepted Submission(s): 12809

Problem Description
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.

Write a program to find and print the nth element in this sequence

 
Input
The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n.
 
Output
For each test case, print one line saying "The nth humble number is number.". Depending on the value of n, the correct suffix "st", "nd", "rd", or "th" for the ordinal number nth has to be used like it is shown in the sample output.
 
Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
 
Sample Output
The 1st humble number is 1.
The 2nd humble number is 2.
The 3rd humble number is 3.
The 4th humble number is 4.
The 11th humble number is 12.
The 12th humble number is 14.
The 13th humble number is 15.
The 21st humble number is 28.
The 22nd humble number is 30.
The 23rd humble number is 32.
The 100th humble number is 450.
The 1000th humble number is 385875.
The 5842nd humble number is 2000000000.
题意:
如果一个数的因子只有2,3,5,7那么这个数叫差数,此题就是求第n个差数是多少?
分析:
求第n个a[n],则肯定是前面的第n-1个数中的某一个与2,3,5,7中的一个的乘积,取最小的哪一个,取的哪一个对应的指针就向前移动一位
 
#include<bits/stdc++.h>
#define max_v 5850
int i2=1,i3=1,i5=1,i7=1,i;
int a[max_v];
using namespace std;
int f()
{
int x=min ( min ( 2*a[i2], 3*a[i3] ),
min ( 5*a[i5], 7*a[i7] ) );
if(x==2*a[i2])
{
++i2;
}else if(x==3*a[i3])
{
++i3;
}else if(x==5*a[i5])
{
++i5;
}else if(x==7*a[i7])
{
++i7;
}
return x;
}
int main()
{
a[0]=0;
a[1]=1;
for(i=2;i<max_v;i++)
{
a[i]=f();
if(a[i]==a[i-1])
{
i--;
}
}
int n;
while(~scanf("%d",&n))
{
if(n==0)
break;
printf("The %d",n);
if(n%100==11||n%100==12||n%100==13)
{
printf("th ");
}else if(n%10==1)
{
printf("st ");
}else if(n%10==2)
{
printf("nd ");
}else if(n%10==3)
{
printf("rd ");
}else
{
printf("th ");
}
printf("humble number is %d.\n",a[n]);
}
return 0;
}

  

HDU 1058(打表)的更多相关文章

  1. hdu 1058 dp.Humble Numbers

    Humble Numbers Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Subm ...

  2. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  3. HDU 1058 Humble Numbers(离线打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...

  4. hdu 4542 打表+含k个约数最小数

    http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ...

  5. HDU 1223 打表 + 大数

    http://acm.hdu.edu.cn/showproblem.php?pid=1223 一般遇到这些题,我都是暴力输出前几项,找规律.未果. 然后输出n = 1时候,以A开始,有多少个答案, n ...

  6. hdu 1058 Humble Numbers

    这题应该是用dp来做的吧,但一时不想思考了,写了个很暴力的,类似模拟打表,然后排序即可,要注意的是输出的格式,在这里wa了一发,看了别人的代码才知道哪些情况没考虑到. #include<cstd ...

  7. hdu 3652 打表

    思路:直接打表 #include<cstdio> #include<vector> #include<cmath> #include<iostream> ...

  8. hdu 5183 hash表

    BC # 32 1002 题意:给出一个数组 a 和一个数 K ,问是否存在数对( i , j ),使 a i   - a i + 1 +……+ (-1)j - i  a j : 对于这道题,一开始就 ...

  9. hdu 4715(打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4715 思路:先打个素数表,然后判断一下就可以了. #include<iostream> # ...

随机推荐

  1. Thymeleaf学习记录(5)--运算及表单

    Thymeleaf文本及预算: 字面 文本文字:'one text','Another one!',... 号码文字:0,34,3.0,12.3,... 布尔文字:true,false 空字面: nu ...

  2. BZOJ4589: Hard Nim(FWT 快速幂)

    题意 题目链接 Sol 神仙题Orzzzz 题目可以转化为从\(\leqslant M\)的质数中选出\(N\)个\(xor\)和为\(0\)的方案数 这样就好做多了 设\(f(x) = [x \te ...

  3. HTML5 Canvas中绘制椭圆的几种方法

    1.canvas自带的绘制椭圆的方法 ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)是后来 ...

  4. vlan配置命令

    # 为VLAN10 指定一个描述字符串“connect to LAB1”.<Sysname> system-viewSystem View: return to User View wit ...

  5. 仿小米便签图文混排 EditText解决尾部插入文字bug

    一直想实现像小米便签那样的图文混排效果,收集网上的办法无非三种: 1.自定义布局,每张图片是一个ImageView,插入图片后插入EditText,缺点是实现复杂,不能像小米便签那样同时选中图片和文字 ...

  6. 应用程序和Activity

    Android 应用程序的组成部分 Android应用程序由各个组件组成,并使用Manifest绑定到一起,Manifest描述了每一个组件和它们之间的交互方式,还用于指定权限,硬件,平台以及应用程序 ...

  7. C语言指针数组(每个元素都是指针)

    转载:http://c.biancheng.net/cpp/html/3246.html 注意:数组指针的区别 如果一个数组中的所有元素保存的都是指针,那么我们就称它为指针数组.指针数组的定义形式一般 ...

  8. Spring Boot框架搭建

    用idea搭建Springboot还是很方便的 环境变量是JDK1.8 SpringBoot自带了Tomcat启动也很方便 1.创建项目 2. 3.选择SpringBoot的版本以及组件 4.创建完成 ...

  9. cache2go开源项目的回调方法使用

    https://github.com/muesli/cache2go 结构体 type CacheTable struct { sync.RWMutex . name string items map ...

  10. python基础——Linux系统下的文件目录结构

    单用户操作系统和多用户操作系统 单用户操作系统:指一台计算机在同一时间只能由一个用户使用,一个用户独自享用系统的全部硬件和软件资源. 多用户操作系统:指一台计算机在同一时间可以由多个用户使用,多个用户 ...