HDU 1032 The 3n + 1 problem
来源:互联网 发布:单片机模块化编程pdf 编辑:程序博客网 时间:2024/05/20 12:51
/*2015年2月26日14:46:01思路很容易想到:第一步:求每个数的Cycle第二步:用当前的Cycle和maxCycle比较有些细节要注意:(1)、小心使用全局变量,不然会出现累加效果(2)、每次输入一组数据后记得要把maxCycle清零*/# include <stdio.h>//int maxCycle = 0; //谨慎使用全局变量,很容出错int countCycle(int n,int count){if(n == 1) {count++;return count;}if((n % 2) != 0) {n = 3*n + 1;count++;countCycle(n,count);}else{n = n/2;count++;countCycle(n,count);}}/*void max(int cycle){if(maxCycle < cycle)maxCycle = cycle;}*/int main(void){int i,j;while(scanf("%d %d",&i, &j)!=EOF){ int currentCycle;int maxCycle;int temp = 0;getchar(); //吸收回车符。if((i <= 0) && (j <= 0))break;while((j - i) >= 0){currentCycle = countCycle(i,temp);//max(currentCycle);if(maxCycle < currentCycle){maxCycle = currentCycle;}i++;}printf("%d\n",maxCycle);maxCycle = 0; }return 0;}
0 0
- hdu 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu-1032-The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- hdu 1032 The 3n + 1 problem
- HDU 1032 The 3n + 1 problem
- selector
- 浅谈WebLogic和Tomcat
- Android应用如何支持屏幕多尺寸多分辨率问题
- Google 开源 C/C++ 版 MapReduce 框架
- hook的使用
- HDU 1032 The 3n + 1 problem
- PlayFramework Play2 Java 关于解决在eclipse建立 views html 模板无法提示
- C#中的线程1
- java版快速排序
- mysql ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
- Java开发中的23种设计模式详解
- 命名规范
- JQuery 的eq和get方法的区别
- <cocos2dx 随记> 关于cocos2dx接Android sdk的一些坑