杭电 1032 The 3n+1问题
2013-02-25 10:08
190 查看
这是杭电上的一道简单题,我很意外我的代码可以AC,我以为这样写会超时!
本来是想建立一个表,通过查表的形式我觉得效率会更高一些,可是在建表的过程中,表中的数据实在难搞(也可能是我
没发现规律),建表问题暂且搁置!
View Code
本来是想建立一个表,通过查表的形式我觉得效率会更高一些,可是在建表的过程中,表中的数据实在难搞(也可能是我
没发现规律),建表问题暂且搁置!
View Code
#include <stdio.h> #include <stdlib.h> int counter( int n ) { int cnt = 1; while( n != 1 ) { if( !(n%2) ) { n = n/2; cnt++; } else { n = 3*n+1; cnt++; } } return cnt; } int main(int argc, char *argv[]) { int m, n, i, cnt, max ; while( scanf( "%d %d", &m, &n ) != EOF ) { printf( "%d %d ", m, n ); if( m > n ) { m = m + n; n = m - n; m = m - n; } max = 0; for( i = m; i <= n; i++ ) { cnt = counter(i); if( max < cnt ) max = cnt; } printf( "%d\n", max ); } system("PAUSE"); return 0; }
相关文章推荐
- HDOJ, 杭电1032, The 3n+1 problem. POJ, 北大OJ,1207....数学题。。又一发
- HDU-1032 The 3n+1 problem 模拟问题(水题)
- UVA 100 && HDU 1032 The 3n+1问题 (扑街题)
- HDU杭电1026 Ignatius and the Princess I(迷宫问题bfs)
- UVa Problem 100 The 3n+1 problem (3n+1 问题)
- 杭电OJ(HDOJ)1032题:The 3n + 1 problem(穷举,水题)
- 杭电1032:The 3n + 1 problem
- 杭电ACM HDU 1032 The 3n + 1 problem
- HDOJ 1032 The 3n+1 problem
- UVa Problem 100 The 3n+1 problem (3n+1 问题)+1 问
- 杭电 acm 1032 The 3n + 1 problem
- 关于杭电1405 The Last Practice 的问题
- HDU 1032(3n+1问题)
- 杭电 HDU 1032 The 3n + 1 problem
- UVA 100 - The 3n+1 problem (3n+1 问题)
- UVA 100 - The 3n+1 problem (3n+1 问题)
- HDU 1032 The 3n+1 Problem
- hdu 1032 The 3n+1 problem
- The 3n + 1 problem(杭电1032)(暴力求解)
- A1031 The 3n+1 problem (3n+1 问题)