题目链接:

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. 解决:springmvc maven 项目搭建完后没有src目录,而且maven导入很慢

    前言:在搭建springmvc maven项目中遇到的问题做总结,比如搭建后没有src,同时这里也解决了搭建后maven导入很慢的问题. 问题: 1.发现创建出来的maven项目没有src文件 ,而且 ...

  2. android中利用HttpURLConnection进行Get、Post和Session读取页面。

    直接上代码,调用的时候要放在线程中. package slj.getsms; import java.io.BufferedReader; import java.io.InputStreamRead ...

  3. [HNOI2006]最短母串问题

    题目大意:给定一个字符串集,求一个最短字串,使得该集合内的串都是该串的一个子串 算法:AC自动机+最短路+状压DP 注意空间限制 #include"cstdio" #include ...

  4. Luogu 4240:毒瘤之神的考验

    传送门 Sol 分开考虑 \(\varphi(ij)\) 中 \(ij\) 的质因子 那么 \[\varphi(ij)=\frac{\varphi(i)\varphi(j)gcd(i,j)}{\var ...

  5. Catalan数的通项公式(母函数推导)

    首先 \[h_n=\sum_{i}h_ih_{n-i-1}\] 写出 \(h\) 的母函数 \(H(x)\) 那么 \[H(x)=H^2(x)x+1,H(x)=\frac{1-\sqrt{1-4x}} ...

  6. jQuery的attr()与prop()的区别

    jQuery的attr()与prop()都是用于获取与设置属性的,但它们又各有不同. attr()一般是用于设置默认值,prop()一般是用于设置属性值,即对于像“diabled”,"che ...

  7. MongoDB for Java

    开发环境 操作系统:Windows7 IDE: MyEclipse Database: MongoDB 开发依赖库 bson-3.0.1.jar mongodb-driver-3.0.1.jar mo ...

  8. 【javascript】javascript设计模式之单例模式

    单例模式: 定义:单例模式之所以这么叫,是因为它限制一个类只能有一个实例化对象. 实现方法:判断实例是否存在,如果存在则直接返回,如果不存在就创建了再返回.(确保一个类只有一个实例对象) 特点: 命名 ...

  9. PGIS大数据量点位显示方案

    PGIS大数据量点位显示方案 问题描述 PGIS在地图上显示点位信息时,随点位数量的增加浏览器响应速度会逐渐变慢,当同时显示上千个点时浏览器会变得非常缓慢,以下是进行的测试: 测试环境: 服务器: C ...

  10. ISO14971-2007阅读

    1.什么是风险? 风险的概念,公认的组成有两部分: 损害发生的概率 损害的后果,即损坏的严重性 2.风险管理的适用范围? 适用于医疗器械生命周期所有阶段 不适用于临床判断 不要求具体的质量体系,但14 ...