poj 1207 The 3n + 1 problem

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 31186 Accepted: 9728

这一道题太水了,竟然暴力都能过,我也就啥都不说了!

代码:

 

  
    
1 #include < stdio.h >
2   int test( int s)
3 {
4 int t;
5 if (s == 1 )
6 return 1 ;
7 if (s % 2 == 0 )
8 t = test(s / 2 );
9 else
10 t = test( 3 * s + 1 );
11 return t + 1 ;
12 }
13   int main()
14 {
15 int i,j,max,k,s,e,t;
16 while (scanf( " %d%d " , & i, & j) != EOF)
17 {
18 max = 0 ;
19 if (i > j)
20 {
21 s = j;
22 e = i;
23 }
24 else
25 {
26 s = i;
27 e = j;
28 }
29 for (k = s;k <= e;k ++ )
30 {
31 t = test(k);
32 if (t > max)
33 max = t;
34 }
35 printf( " %d %d %d\n " ,i,j,max);
36 }
37 return 0 ;
38 }
39

 

你可能感兴趣的:(poj)