hdu 1058 Humble Numbers (DP)
2014-04-24 10:36
411 查看
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15978 Accepted Submission(s): 6915
[align=left]Problem Description[/align]
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
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
[align=left]Sample Output[/align]
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.
[align=left]Source[/align]
University of Ulm Local Contest 1996
[align=left]Recommend[/align]
JGShining | We have carefully selected several similar problems for you: 1421 1024 1505 2577 2870
简单DP,有点巧妙:
//93 MS 228 KB GNU C++ #include<stdio.h> int ans[6000]; inline int Min(int a,int b) { return a<b?a:b; } void init() { int m1=0,m2=0,m3=0,m4=0; int t1,t2,t3,t4; ans[0]=1; int i=1; while(i<5842){ t1=ans[m1]*2; t2=ans[m2]*3; t3=ans[m3]*5; t4=ans[m4]*7; int tmp=Min(Min(t1,t2),Min(t3,t4)); ans[i++]=tmp; if(tmp==t1) m1++; if(tmp==t2) m2++; if(tmp==t3) m3++; if(tmp==t4) m4++; } } int main(void) { int n; init(); while(scanf("%d",&n)!=EOF && 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",ans[n-1]); } return 0; }
相关文章推荐
- hdu 1058 Humble Numbers【dp】
- hdu 1058:Humble Numbers(动态规划 DP)
- 【HDU】-1058-Humble Numbers(DP)
- hdu 1058 Humble Numbers (dp)
- hdu1058 Humble Numbers(丑数) —— dp
- hdu 1058 Humble Numbers(DP)
- HDU 1058 Humble Numbers (DP)
- zoj 1095 || hdu 1058 Humble Numbers( DP || 乱搞)
- HDOJ(HDU).1058 Humble Numbers (DP)
- 定义代码Hdu 1058 Humble Numbers(dp)
- hdu 1058 dp.Humble Numbers
- DP Problem D:Humble Numbers(HDU 1058)
- HDU 1058 Humble Numbers(dp)
- HDU 1058 Humble Numbers(DP,数)
- HDU 1058 Humble Numbers && NOJ 1420 丑数 (数位dp)
- HDU 1058 Humble Numbers【DP】
- hdu 1058 Humble Numbers (DP初步)
- HDU-1058 Humble Numbers(线性dp 枚举因子个数)
- HDU 1058.Humble Numbers【这个题怎么定位呢···就【DP】吧】【8月28】
- 【HDU】1058 - Humble Numbers(dp)