Humble Numbers 丑数 简单dp(思路
来源:互联网 发布:mix滤镜大师mac版 编辑:程序博客网 时间:2024/06/05 12:26
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1198 Accepted Submission(s): 645Problem 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
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
1234111213212223100100058420
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 <algorithm>#include <string.h>#include <cmath>#include <stdio.h>#include <vector>#include <map>#include <queue>#include <utility>using namespace std;typedef long long ll;int a[100005];ll dp[100005];ll min(ll a, ll b, ll c, ll d) { return min(min(a, b), min(c, d));}void init(){ int i = 1; dp[1] = 1; int p2, p3, p5, p7; p2 = p3 = p5 = p7 = 1; while (i <= 5842) { dp[++i] = min(dp[p2]*2, dp[p3]*3, dp[p5]*5, dp[p7]*7); if (dp[i] == dp[p2]*2) p2++; if (dp[i] == dp[p3]*3) p3++; if (dp[i] == dp[p5]*5) p5++; if (dp[i] == dp[p7]*7) p7++; }}int main(){ int n; init(); while(scanf("%d", &n) != EOF && n) { if(n%10 == 1 && n%100 != 11) printf("The %dst humble number is %lld.\n",n,dp[n]); else if(n%10 == 2 && n%100 != 12) printf("The %dnd humble number is %lld.\n",n,dp[n]); else if(n%10 == 3 && n%100 != 13) printf("The %drd humble number is %lld.\n",n,dp[n]); else printf("The %dth humble number is %lld.\n",n,dp[n]); }}
0 0
- Humble Numbers 丑数 简单dp(思路
- zoj 1095 Humble Numbers(丑数+dp)
- Humble Numbers 丑数
- HDU 1058 Humble Numbers && NOJ 1420 丑数 (数位dp)
- hdu1058 Humble Numbers(丑数) —— dp
- Humble Numbers(丑数)
- USACO : Humble Numbers (丑数)
- hdu 1058 Humble Numbers【丑数】
- USACO 3.1.3 Humble Numbers 丑数
- HDU 丑数 - 1058 Humble Numbers
- 堆----【USACO3.1.3】Humble Numbers丑数
- 【HDU-1058】Humble Numbers 丑数
- hdu 1058 Humble Numbers 丑数
- HDOJ1058 Humble Numbers丑数的问题
- USACO 3.1 Humble Numbers丑数
- usaco ★Humble Numbers 丑数
- USACO 3.1 Humble Numbers丑数
- USACO 3.1 丑数 Humble Numbers
- 【caffe】基于CNN的年龄和性别检测
- 《精彩绝伦的CSS》——选择器(三)特殊性和重要性
- 数据库笔记(SQL之视图、事务、约束以及权限)
- NGUI之Toggle
- Java垃圾回收无效线程吗?
- Humble Numbers 丑数 简单dp(思路
- react-基础-入门第二篇;对于我们这些菜鸟来说,并不是仅仅想要hello word
- 算法导论(Exercise 4.1-5)
- O..One..One...Day
- 如何在Ubuntu下安装VMwaretools
- ThinkPHP5实现注册激活邮件
- 29-TCP 协议(持续定时器)
- SQL复习
- [notes]深入理解java虚拟机