hdu 1032(打表水过)

 1 #include<stdio.h>
 2 #include<algorithm>
 3 using namespace std;
 4 #define maxn 1000001
 5 __int64 a[maxn];
 6 void init()
 7 {
 8     __int64 i,temp;
 9     __int64 count;
10     for(i=1;i<maxn;i++)
11     {
12         count=1;
13         temp=i;
14         while(temp!=1)
15         {
16             if(temp%2==0)
17                 temp/=2;
18             else
19                 temp=temp*3+1;
20             count++;
21         }
22         a[i]=count;
23     }
24 } 
25 int main()
26 {
27     int x,y,temp;
28     int i;
29     int max;
30     init();
31     while(scanf("%d%d",&x,&y)!=EOF)
32     {
33         max=-1;
34         printf("%d %d ",x,y);
35         if(x>y)swap(x,y);
36         for(i=x;i<=y;i++)
37         {
38             if(max<a[i])
39                 max=a[i];
40         }
41         printf("%d\n",max);
42     }
43     return 0;
44 }

 

posted @ 2012-08-10 14:56  M_cag  阅读(180)  评论(0编辑  收藏  举报