题目链接:

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. 分ip统计网站访问次数

    package web.listener; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; ...

  2. 《JavaWeb从入门到改行》过滤器学习笔记

    >"; display: block; height: 0; clear: both; visibility: hidden; } #sitemap, #sitemap ul{disp ...

  3. HTML基本结构及标签样式

    <!DOCTYPE html>————声明 <html> <head>————头部设置信息 <title>文件标题</title> < ...

  4. System.out.println与System.err.println的区别

    public class Test2 { static { System.out.println("1"); } { System.out.println("2" ...

  5. JS原生带小白点轮播图

    咱们刚刚说了js原生轮播图,现在给他加上可以随着一起走动的小圆点吧! css代码: *{ margin:0px; padding: 0px; } ul{ width: 2500px; height: ...

  6. laravel model relationship

    laravel支持多种模型之间的relation,对应着模型间的one2one, one2many,many2many,hasManyThrough,Polymorphic, many2many po ...

  7. 为什么懂云的IT高手能过得比你好

    盼望着,盼望着,一年一度的国庆7天长假还有不到24小时就到来了.各个部门的同事都已准备好满世界旅行去了. IT 部门各位同事的心还是悬着,信息系统还要持续的运转,对外的网站不能停,假期的线上促销也不能 ...

  8. CentOS随笔 - 6.CentOS7安装Git服务器

    前言 转帖请注明出处: http://www.cnblogs.com/Troy-Lv5/ 版本管理当然是选择git..反正我是被svn坑怕了... 这次安装的是git 2.18.0 点击下载 准备安装 ...

  9. 【Oracle】锁表处理 SQL 错误: ORA-00054: 资源正忙, 但指定以 NOWAIT 方式获取资源, 或者超时失效

    问题描述有时候ORACLE数据的某些表由于频繁操作,而且比较大,会导致锁表(死锁). 问题分析(1)锁的分析ORACLE里锁有以下几种模式:0:none1:null 空2:Row-S 行共享(RS): ...

  10. select server

    server with select #include<stdio.h> #include<sys/types.h> #include<sys/socket.h> ...