水题。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1032 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #define MAX_LEN  10000001
 5 
 6 __int64 count = 0;
 7 __int64 Geted[MAX_LEN] = {0};
 8 
 9 
10 void swap( __int64 &a, __int64 &b )  
11 {  
12     __int64 temp = a;  
13     a = b;  
14     b = temp;  
15 }  
16 
17 void GetMaxL(__int64 n)
18 {
19     count++;
20     if(n == 1return ;
21     if(n & 1) GetMaxL(3 * n + 1);
22     else GetMaxL( n/2 );
23 }
24 
25 
26 int cmp(const void *a , const void *b)
27 {
28     return *(int*)b - *(int*)a;
29 }
30 
31 int main()
32 {
33     __int64 i ;
34     __int64 beg , end;
35     while(~scanf("%I64d%I64d", &beg , &end))
36     {
37       if(beg > end)
38       {
39             swap(beg , end);
40       }
41       
42       __int64 sum = 0;
43       for(i = beg ; i <= end ;i++)
44       {
45         count = 0;
46         GetMaxL(i);
47         Geted[sum++] = count;
48       }
49       
50       qsort(Geted , sum , sizeof(Geted[0]) , cmp);
51       printf("%I64d %I64d " , beg , end);
52       printf("%I64d\n", Geted[0]);
53     }
54     return 0;

55 } 

 

posted on 2012-05-20 16:08  有间博客  阅读(191)  评论(0编辑  收藏  举报