DP————1004
来源:互联网 发布:定额软件有哪些 编辑:程序博客网 时间:2024/06/11 16:31
题目:humple number
题意:在(0,5842)范围内求仅有2,3,5,7因子的数列,如1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27。。。为前20个humple number
思路:显然,第一个为1,这个数列按从小到大排列,因子只有2,3,5,7四个数,所以第二个数为2,第三个为3,第 四个为2*2,第五个为5,第六个为3*2,第七个为7,而第八个为2*2*2........ 数列中关于2的与2的倍数有关, 若此次选择的为2的倍数,下一个关于2的数一定是这次选择的倍数乘2。3,5,7一样
感想:在前20个数中查找规律
代码:
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
long long int hum[5866];
hum[1]=1;
int a,b,c,d;
a=b=c=d=1;
int i;
for(i=2;i<5844;i++)
{
hum[i]=min(hum[a]*2,min(hum[b]*3,min(hum[c]*5,hum[d]*7)));
if(hum[i]==hum[a]*2)
a++;
if(hum[i]==hum[b]*3)
b++;
if(hum[i]==hum[c]*5)
c++;
if(hum[i]==hum[d]*7)
d++;
}
int n;
while(~scanf("%d",&n)!=EOF,n)
{
if(n%10==1&&n%100!=11)
scanf("The %dst humble number is %d.\n",n,hum[n]);
else if(n%10==2&&n%100!=12)
scanf("The %dnd humble number is %d.\n",n,hum[n]);
else if(n%10==3&&n%100!=13)
scanf("The %drd humble number is %d.\n",n,hum[n]);
else
scanf("The %dth humble number is %d.\n",n,hum[n]);
}
return 0;
}
- DP——HDU2571:命运(DP)
- zoj2745——dp
- hdu4427——dp
- hdu4433——dp
- hdu4455——dp
- 滑雪——dp
- Minimal——dp
- hdu_1087——dp
- dp——vijos1207
- PKUOJ—DP专辑
- poj2342—树形dp
- DP —> 背包问题
- dp—完全背包
- (DP)POJ2192—Zipper
- DP————1004
- DP——树形DP——HDOJ1620
- DP———1001
- DP———1002
- HDU-ACM2040
- 设计模式初探(一)
- 猜数字
- Unable to add App ID because the ’10’ app id limit in ‘7’ days has been exceeded
- MIME编码介绍
- DP————1004
- Linux C++ 服务器端这条线怎么走?一年半能做出什么?
- Intro to Configure IPsec VPN (Gateway-to-Gateway ) using Strongswan
- IO
- 数据处理问题
- HDU-ACM2041
- bzoj 2440: [中山市选2011]完全平方数
- activity下android:launchMode四种模式
- 用Java写解谜RPG-3.MVC下的开始界面和所谓按钮