Hdoj1032 simple questions

From , 3 Years ago, written in C++, viewed 52 times.
URL https://pastebin.vip/view/c366c2c9
  1. #include <iostream>  
  2. #include <vector>  
  3. using namespace std;  
  4. int main()  
  5. {  
  6.     int m,n;  
  7.     while (cin>>m>>n)  
  8.     {  
  9.         int result=0,max,min;  
  10.         //①此处最为关键,因为题目中并未指明输入大的在前  
  11.         if(m<=n)  
  12.         {  
  13.             min=m;  
  14.             max=n;  
  15.         }  
  16.         else  
  17.         {  
  18.             min=n;  
  19.             max=m;  
  20.         }  
  21.         for(int i=min;i<=max;i++)  
  22.         {  
  23.             int count=0;  
  24.             int temp=i;  
  25.             while(temp!=1)  
  26.             {  
  27.                 count++;  
  28.                 if(temp%2)  
  29.                     temp=3*temp+1;  
  30.                 else  
  31.                     temp=temp/2;  
  32.             }  
  33.             //②最终的终止未计算在内,所以需要+1  
  34.             count++;  
  35.             if (count>result)  
  36.                 result=count;  
  37.         }  
  38.         cout<<m<<" "<<n<<" "<<result<<endl;  
  39.     }  
  40. }  
  41.  

Reply to "Hdoj1032 simple questions"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website