各种水 题目是简单使用动态规划 使用已有的动态规划进行推导
先上代码
1
2
3
5
7
1 2
4
3
5
7
1 2 3
4
6
5
7
最后注意输出 即可
/* Name: Copyright: Author:yujiaao Date: Description:hdu */ #include<iostream> #include<cstdio> using namespace std; int list[5845]; int f_min(int a,int b,int c,int d) { int m=a<b?a:b; int n=c<d?c:d; return n<m?n:m; } int main() { // freopen("C:\\Users\\yujiaao\\Desktop\\测试专用\\in.txt","r",stdin); // freopen("C:\\Users\\yujiaao\\Desktop\\测试专用\\out.txt","w",stdout); list[0]=1; int i2=0,i3=0,i5=0,i7=0; int i=0; int temp; int n; for(i=1;i<5843;i++) { list[i]=f_min(2*list[i2],3*list[i3],5*list[i5],7*list[i7]); if(list[i]%2==0) i2++; if(list[i]%3==0) i3++; if(list[i]%5==0) i5++; if(list[i]%7==0) i7++; } while(scanf("%d",&n)!=EOF &&n!=0) { if(n%10==1&&n%100!=11) printf("The %dst humble number is %d.\n",n,list[n-1]); else if(n%10==2&&n%100!=12) printf("The %dnd humble number is %d.\n",n,list[n-1]); else if(n%10==3&&n%100!=13) printf("The %drd humble number is %d.\n",n,list[n-1]); else printf("The %dth humble number is %d.\n",n,list[n-1]); } system("pause"); return 0; }