标签:
1 /*看题解AC的,结果开始开编译错误了几次,oj说是min()没定义,那为什么自己编译会通过,然后自己写了min(),dp方程 dp[i]=f[i]=min(f[a]*2,min(f[b]*3,min(f[c]*5,f[d]*7)))*/ 2 #include<stdio.h>/*dev编译后运行程序中途闪退,提交后却对的*/ 3 using namespace std; 4 int min(int a,int b) 5 { 6 return a>b?b:a; 7 } 8 int humble[5843]; 9 void factor()/*马丹看了半天也是似懂非懂,比赛时完全想不出来这么求*/ 10 { 11 int post1=1,post2=1,post3=1,post4=1,na,nb,nc,nd,i; 12 humble[1]=1; 13 for(i=2;i<=5843;i++) 14 { 15 humble[i]=min(na=humble[post1]*2,min(nb=humble[post2]*3,min(nc=humble[post3]*5,nd=humble[post4]*7))); 16 if(humble[i]==na) post1++; 17 if(humble[i]==nb) post2++; 18 if(humble[i]==nc) post3++; 19 if(humble[i]==nd) post4++; 20 } 21 } 22 int main() 23 { 24 int n; 25 factor(); 26 while(~scanf("%d",&n)) 27 { 28 if(n==0) 29 break; 30 printf("The %d",n); 31 if(n%100!=11&&n%10==1) 32 printf("st"); 33 else if(n%100!=12&&n%10==2) 34 printf("nd"); 35 else if(n%100!=13&&n%10==3) 36 printf("rd"); 37 else 38 printf("th"); 39 printf(" humble number is %d.\n",humble[n]); 40 } 41 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4498976.html