本文主要是介绍hdu 1032,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
import java.util.Scanner;
public class Main
{ static int len;static void three(int n){len++;if(n==1) return ;if(n%2==1) n=3*n+1;else n=n/2;three(n);}public static void main(String args[]){int n,m;Scanner cin=new Scanner(System.in);while(cin.hasNext()){n=cin.nextInt();m=cin.nextInt();System.out.print(n+" "+m+" ");if(m>n){int t=m;m=n;n=t;}int max=0;for(int i=m;i<=n;i++){len=0;three(i);if(max<len)max=len;}System.out.println(max);}}
}
这篇关于hdu 1032的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!