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 ...
随机推荐
- JVM调优总结:一些概念
数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:他代表的值就是数值本身:而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对象本身, ...
- Linux命令学习-图形化界面命令开关闭
su root password 1, 关闭图形界面: init 3 关闭图形界面(XServer服务也会关闭) 开启图形界面: init 5 或 startx 开机时,不进入 X Window: v ...
- 【BZOJ】2331: [SCOI2011]地板 插头DP
[题意]给定n*m的地板,有一些障碍格,要求用L型的方块不重不漏填满的方案数.L型方块是从一个方格向任意两个相邻方向延伸的方块,不能不延伸.n*m<=100. [算法]插头DP [题解]状态0表 ...
- 【LibreOJ】#6257. 「CodePlus 2017 12 月赛」可做题2
[题意]数列满足an=an-1+an-2,n>=3.现在a1=i,a2=[l,r],要求满足ak%p=m的整数a2有多少个.10^18. [算法]数论(扩欧)+矩阵快速幂 [题解]定义fib(i ...
- js面向对象的几种常见写法
下面是一个简单的js对象:定义Circle类,拥有成员变量r,常量PI和计算面积的成员函数area(),常用为第一种和第三种. 1.工厂方式 var Circle = function() { var ...
- node的简单爬虫
最近在学node,这里简单记录一下. 首先是在linux的环境下,关于node的安装教程: https://github.com/alsotang/node-lessons/tree/master ...
- 设置display:inline-block产生间隙
display:inline-block产生间隙,是由于换行在内的空白符 display:inline-block在IE下仅仅是触发了layout,而它本是行布局,触发后,块元素依然还是行布局.所以需 ...
- python初步学习-异常
异常 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在python无法正常处理程序时就会发生一个异常. 异常是python对象,表示一个错误. 当python脚本 ...
- Oracle笔记之序列(Sequence)
Oracle中序列是一种数据对象,可以视为一个等差数列,我们自增就是一个遍历这个数列的过程,可以取当前值,也可以将当前值自加n后返回,Sequence与表没有太大的关系,有的时候如果表的主键是数值类型 ...
- C# 动态调取 soap 接口
调用示例 string url = "http://localhost:8080/server/PatientService.asmx"; Hashtable ht = new H ...