hdu 1058 dp.Humble Numbers
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Write a program to find and print the nth element in this sequence
Input
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.
#include <iostream>
#include <stdio.h>
using namespace std;
int f[5843],n;
int i,j,k,l; int min(int a,int b,int c,int d)
{
int min=a;
if(b<min) min=b;
if(c<min) min=c;
if(d<min) min=d; if(a==min) i++;
if(b==min) j++;
if(c==min) k++;
if(d==min) l++; return min;//a或b或c或d
} int main()
{
i=j=k=l=1;
f[1]=1;
for(int t=2; t<=5842; t++)
{
f[t]=min(2*f[i],3*f[j],5*f[k],7*f[l]);
}
while(scanf("%d",&n)&&n!=0)
{
if(n%10==1&&n%100!=11)
printf("The %dst humble number is %d.\n",n,f[n]);
else if(n%10==2&&n%100!=12)
printf("The %dnd humble number is %d.\n",n,f[n]);
else if(n%10==3&&n%100!=13)
printf("The %drd humble number is %d.\n",n,f[n]);
else
printf("The %dth humble number is %d.\n",n,f[n]);
}
return 1;
} //#include<stdio.h>
//#define min(a,b) (a<b?a:b)
//#define min4(a,b,c,d) min(min(a,b),min(c,d))
//int a[5850];//存放丑数
//
//int main()
//{
// int n=1;
// int p2,p3,p5,p7;
// p2=p3=p5=p7=1;//2,3,5,7的计数器
// a[1]=1;
// while(a[n]<2000000000)//从2开始递推计算,一共5842个丑数
// {
// a[++n] = min4(2*a[p2],3*a[p3],5*a[p5],7*a[p7]);//取最小值,相应的计数器加1
// if(a[n]==2*a[p2]) p2++;
// if(a[n]==3*a[p3]) p3++;
// if(a[n]==5*a[p5]) p5++;
// if(a[n]==7*a[p7]) p7++;
// }
// while(scanf("%d",&n) && n)
// {
// 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("%d.\n",a[n]);
// }
// return 0;
//
//}
hdu 1058 dp.Humble Numbers的更多相关文章
- ACM -- 算法小结(九)DP之Humble numbers
DP -- Humble numbers //一开始理解错题意了,题意是是说一些只有唯一一个质因数(质因数只包括2,3,5,7)组成的数组,请找出第n个数是多少 //无疑,先打表,否则果断 ...
- HDOJ(HDU).1058 Humble Numbers (DP)
HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1058:Humble Numbers(动态规划 DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Humble Numbers HDU - 1058
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...
- HDU 1058 Humble Numbers (动规+寻找丑数问题)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- HDU 1058 Humble Number
Humble Number Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humbl ...
- DP 60题 -3 HDU1058 Humble Numbers DP求状态数的老祖宗题目
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- elasticsearch ik中文分词器的安装配置使用
安装步骤 https://github.com/medcl/elasticsearch-analysis-ik 以插件形式安装: [elsearch@localhost elasticsearch- ...
- [linux]ubuntu在线安装mysql
1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client 3. sudo apt-get install li ...
- 【CodeForces】576 B. Invariance of Tree
[题目]B. Invariance of Tree [题意]给定n个数的置换,要求使n个点连成1棵树,满足u,v有边当且仅当a[u],a[v]有边,求一种方案或无解.n<=10^5. [算法]数 ...
- Calendar 日期类介绍
Calendar c = Calendar.getInstance();//创建实例 默认是当前时刻 c.get(Calendar.YEAR); c.get(Calendar.MONTH); c.ge ...
- redis笔记之两种持久化备份方式(RDB & AOF)
Redis支持的两种持久化备份方式(RDB & AOF) redis支持两种持久化方式,一种是RDB,一种是AOF. RDB是根据指定的规则定时将内存中的数据备份到硬盘上,AOF是在每次执行命 ...
- shell中$*与$@的区别
$*所有的位置参数,被作为一个单词 注意:"$*"必须被""引用 $@ 与$*同义,但是每个参数都是一个独立的""引用字串,这就意味着参数被 ...
- 64_q2
qt3-3.3.8b-69.fc26.x86_64.rpm 13-Feb-2017 01:37 3591906 qt3-MySQL-3.3.8b-69.fc26.i686.rpm 13-Feb-201 ...
- Machine Learning系列--TF-IDF模型的概率解释
信息检索概述 信息检索是当前应用十分广泛的一种技术,论文检索.搜索引擎都属于信息检索的范畴.通常,人们把信息检索问题抽象为:在文档集合D上,对于由关键词w[1] ... w[k]组成的查询串q,返回一 ...
- /proc文件夹介绍
Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它常见的文件系统不同的是,/proc是一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过 ...
- C++卷积神经网络实例(一)
跟着这位博主来学习C++的卷积网络实例,因为作者一直在更新代码,所以新的代码和这位博主的分析有所不同:这位博主写的东西太泛了,没有讲到实质, 可以参考下他分析的类与类之间的关系图.. 前四节:http ...