HDU1058 DP
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24194 Accepted Submission(s): 10596
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 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.
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.
2
3
4
11
12
13
21
22
23
100
1000
5842
0
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.
//从1开始每个humble数依次乘以2,3,5,7,从小到大排列出来,可以简化为f[i]=min(2*f[a],3*f[b],5*f[c],7*f[d]),当然用麻烦的方法也能做。
//注意1,2,3,21,22,23,111,112,113英文单词后缀st,nd,rd;11,12,13,10011,10012,10013,这样的和其他的后缀为th.
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b,c,d;
long long f[];
long min(long A,long B,long C,long D)
{
long MIN=A;
if(B<MIN) MIN=B;
if(C<MIN) MIN=C;
if(D<MIN) MIN=D;
if(MIN==A) a++;
if(MIN==B) b++;
if(MIN==C) c++;
if(MIN==D) d++;
return MIN;
}
int main()
{
a=b=c=d=;
f[]=;
for(int i=;i<=;i++)
f[i]=min(*f[a],*f[b],*f[c],*f[d]);
while(scanf("%d",&n)&&n)
{
if(n%==&&n%!=)
printf("The %dst humble number is %lld.\n",n,f[n]);
else if(n%==&&n%!=)
printf("The %dnd humble number is %lld.\n",n,f[n]);
else if(n%==&&n%!=)
printf("The %drd humble number is %lld.\n",n,f[n]);
else printf("The %dth humble number is %lld.\n",n,f[n]);
}
return ;
}
HDU1058 DP的更多相关文章
- DP 60题 -3 HDU1058 Humble Numbers DP求状态数的老祖宗题目
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu1058丑数(优先队列、暴力打表)
hdu1058 题意:当一个数只有2.3.5.7这四种质因数时(也可以一种都没有或只有其中几种),这个数就是丑数,输出第 n 个丑数是多少: 其实并没有发现hdu把这道题放在 dp 专题里的意图,我的 ...
- DP录 (更新)
补补弱项 全面发展.. 从最基础来 sdut1299最长上升子序 #include <iostream> #include<cstdio> #include<cstrin ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
- AEAI DP V3.7.0 发布,开源综合应用开发平台
1 升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...
- AEAI DP V3.6.0 升级说明,开源综合应用开发平台
AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4026 Solved: 1473[Submit] ...
- [斜率优化DP]【学习笔记】【更新中】
参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...
随机推荐
- JDBC之——一个单线程JDBC基类和一些注意事项
下面的一个DBase基类提供了一些jdbc的基本操作,配置文件的配置部分并不准确,只是在自己机器上的mysql中测试过.. 数据库的增删改方法中都在开始调用了getConnection方法,末尾调用了 ...
- javascript中时间的手动创建date的方式
new Date("month dd,yyyy hh:mm:ss"); new Date("month dd,yyyy"); new Date(yyyy,mth ...
- 智能车学习(十三)——角度控制
一.手册代码以及图示 二.流程说明 1.角度计算函数说明 //===================================================================== ...
- document对象(二)
五.相关元素操作: var a = document.getElementById("id"); 找到a: var b = a.nextSibling ...
- php代码效率测试
对于一个被加载的页面,而遇到会卡的原因 ,代码量大,为了减少一句话分析,就采用分段式判断. 从php手册了解到,使用microtime函数,具体方法可参见php手册对这函数的用法 定义get_exec ...
- 从零开始---控制台用c写俄罗斯方块游戏(1)
从零开始---控制台用c写俄罗斯方块游戏(1) 很少写博文,一来自身知识有限,二来自己知道,已经有很多这样的博文了,三就是因为懒,文笔也一般,四来刚出来工作,时间也不多 之所以写这篇博文,是因为应群里 ...
- C# 键值对类相关
一 C# 键值对类有以下类: ① IDictionary<string, Object> idc = new Dictionary<string, object>(); ...
- 《DSP using MATLAB》示例Example4.12
上代码: b = [0, 1, 1]; a = [1, -0.9, 0.81]; % [R, p, C] = residuez(b,a); Mp = (abs(p))' Ap = (angle(p)) ...
- js-面向对象的程序设计,函数表达式
面向对象的程序设计: 1.属性类型:数据属性.访问器属性 数据属性:wirtable:false –只读:如果尝试为它赋值,会忽略 Configurable:false—不能从对象中删除属性 在调用O ...
- wpf 背景镂空loading.....
第一步,,使用arc控件 ArcThickness="15" StartAngle="-6" EndAngle="6" 2,拉一个Ellip ...