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 ...
随机推荐
- ASCIIHexDecode,RunLengthDecode
public static byte[] ASCIIHexDecode(byte[] data) { MemoryStream outResult = new MemoryStream(); bool ...
- java线程之——synchronized的注意细节
我在学习synchronized的时候,十分好奇当一个线程进入了一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法? 然后就做了个实验(实验代码最后贴出),最后得到了如下 ...
- LaTex学习笔记(一)
1. 语法 命令 普通命令 环境 数据 注释 2. 物理结构 导言 指定文档类型,引入宏包,定义命令,环境等 \documentclass[options]{class} \usepackage[op ...
- 用js实现图片自动加载的瀑布流效果
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- JFreeChart 使用一 饼图之高级特性
原文链接:http://www.cnblogs.com/jtmjx/archive/2013/04/23/jfreechart_advantage.html 本文主要讲解JFreeChart中饼图的一 ...
- 智能车学习(十一)——陀螺仪学习
一.学习说明 感觉就是配置I2C通信,然后直接移植51代码... 二.代码分享: 1.头文件: #ifndef I2C_GYRO_H_ #define I2C_GYRO_H_ /*********** ...
- Zookeeper 初体验之——伪分布式安装(转)
原文地址: http://blog.csdn.net/salonzhou/article/details/47401069 简介 Apache Zookeeper 是由 Apache Hadoop 的 ...
- Sigar介绍与使用
Sigar是Hyperic-hq产品的基础包,是Hyperic HQ主要的数据收集组件.它用来从许多平台收集系统和处理信息. 这些平台包括:Linux, Windows, Solaris, AIX, ...
- BZOJ总览
1040: [ZJOI2008]骑士 树上加了一条边 断边再树形DP 断边调了好久 要了解题目性质 1045: [HAOI2008] 糖果传递 中位数水题 内含数学方程 变量搞一搞 bzoj1053: ...
- JavaScrip实现3D旋转动态效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...