zoj 1095 Humble Numbers
2007-03-02 15:28
381 查看
//code by wshong
#include<stdio.h>
#include<stdlib.h>
int main()
...{
int ham[5842];
int a[4]=...{0,0,0,0};
ham[0] = 1;
int i;
for(i = 1; i < 5842; i++)
...{
int tem1 = 2 * ham[a[0]] > 3* ham[a[1]] ? 3*ham[a[1]]: 2 * ham[a[0]];
int tem2 = 5 * ham[a[2]] > 7 * ham[a[3]]? 7*ham[a[3]]:5 *ham[a[2]];
int temp = tem1 > tem2 ? tem2:tem1;
ham[i] = temp;
if(ham[i] == 2 * ham[a[0]]) a[0]++;
if(ham[i] == 3 * ham[a[1]]) a[1]++;
if(ham[i] == 5 * ham[a[2]]) a[2]++;
if(ham[i] == 7 * ham[a[3]]) a[3] ++;
}
for(i = 0; i < 5842; i++)
printf("%d,",ham[i]);
int n;
while(scanf("%d",&n),n)
...{
if(n % 10 == 1 &&n %100!=11)
printf("The %dst humble number is %d. ",n,ham[n-1]);
else if(n % 10 == 2 && n %100 != 12 )
printf("The %dnd humble number is %d. ",n,ham[n-1]);
else if(n%10 == 3 && n %100!= 13)
printf("The %drd humble number is %d. ",n,ham[n -1]);
else printf("The %dth humble number is %d. ",n,ham[n -1 ]);
}
system("pause");
return 0;
}
/**//*参照了别人的程序,这道题的难点在与怎么确定比现在数大的最小数,题目用的很巧,这种方法很好用!
之前老是超时,要先打表,然后直接就可以读出相应的数的了,算法也很容易明白
*/
相关文章推荐
- zoj 1095 - Humble Numbers
- ZOJ 1095 Humble Numbers (构造)
- zoj1095 Humble Numbers(DP)
- zoj 1095 Humble Numbers
- ZOJ 1095 Humble Numbers
- ZOJ 1095 Humble Numbers
- ZOJ--1095:Humble Numbers
- zoj 1095 Humble Numbers(丑数+dp)
- zoj 1095 || hdu 1058 Humble Numbers( DP || 乱搞)
- zoj1095 Humble Numbers
- ZOJ 1095 Humble Numbers
- 1095 Humble Numbers
- hdu 1058 Humble Numbers 丑数
- HDU 1058 Humble Numbers
- hdu1058 Humble Numbers(思维)
- HDU Humble Numbers
- USACO 3.1 Humble Numbers丑数
- hdu 1085 Humble Numbers(打表)
- HDU1058 Humble Numbers
- LightOJ-1095 Arrange the Numbers