您的位置:首页 > 其它

hdoj 1058 Humble Numbers(dp)

2012-10-25 17:43 519 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1058

st[i]=min{st[a]*2,st[b]*3,st[c]*5,st[d]*7}

View Code

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
long int n;
long int st[5850];
long int a=1,b=1,c=1,d=1,small,i;
st[1]=1;
for(i=2;i<5850;i++)
{
small=st[a]*2;
if(small>st[b]*3)
small=st[b]*3;
if(small>st[c]*5)
small=st[c]*5;
if(small>st[d]*7)
small=st[d]*7;
if(small==st[a]*2)
a++;
if(small==st[b]*3)
b++;
if(small==st[c]*5)
c++;
if(small==st[d]*7)
d++;
st[i]=small;
}
while(scanf("%ld",&n))
{
if(n==0)
break;
if(n%10==1&&n%100!=11)
printf("The %ldst humble number is %ld.\n",n,st
);
else if(n%10==2&&n%100!=12)
printf("The %ldnd humble number is %ld.\n",n,st
);
else if(n%10==3&&n%100!=13)
printf("The %ldrd humble number is %ld.\n",n,st
);
else
printf("The %ldth humble number is %ld.\n",n,st
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: