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 ...
随机推荐
- LoadRunner11录制APP脚本(1)
1.测试准备: a.首先安装LoadRunner11.0的版本跟新
- JAVA Day5
数组 1.数组是一组变量的集合,存储“相同数据类型”的一组数据: 连续的空间. 2.声明一个变量就是在内存空间划出一块合适 ...
- ViewPager的广告条轮播
首先布局 <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:androi ...
- OAuth2.0 在 SSO中的应用~
关于OAuth2.0的介绍,请看下面链接(讲的挺好的): http://blog.csdn.net/seccloud/article/details/8192707 我的理解: 一共四个角色,A:Cl ...
- [自动运维]ant脚本打包,上传文件到指定服务器,并部署
1.根节点使用,表示根目录为当前目录,默认启动的target为build,项目名称为othersysm, <project basedir="." default=" ...
- json解析不推荐使用eval
推荐使用JSON.parse() 低版本浏览器(IE6/7)不支持此方法,可以通过网上下载json2.js,引入到文件中,此文件通过判断浏览器是否支持JSON.parse()方法,如果不支持,文件中编 ...
- http://www.roncoo.com/article/detail/124661
http://www.roncoo.com/article/detail/124661
- 解决$.getJSON在IE浏览器下出现数据缓存,第一次访问某个后台路径之后,再次访问该路径不再走后台的方法。
最近写代码的时候遇到一个小问题,我用的是火狐,项目里测试人员用的是IE,当用jquery的getjson函数从后台获取数据的时候,IE浏览器会自动设置缓存,如果此时你对数据进行修改的时候刷新页面,IE ...
- 关于listView 中的聚焦问题
我在使用listView+adapter 中,遇到一个问题,就是item项添加了若干个可以被监听的控件后 在listView中的setOnItemClickListener失效了 原因是焦点已经在it ...
- 在Spring-Mybatis-Restful中配置多数据源的properties文件
在Spring的配置文件中,如下: <?xml version="1.0" encoding="utf-8"?> <beans xmlns=& ...