Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

果断中招

Posted by howling at 2011-07-29 13:10:01 on Problem 1207
#include<iostream>
using namespace std;
int cal(int n){
    int count=0;
    while(n!=1){
        count++;
        if(n%2==0)n=n/2;
        else n=3*n+1;
    }
    count++;
    
    return count;
}
int main (){
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF){
        int max=0;
        bool flag=true;
        if(a>b){
            int c=b;
            b=a;
            a=c;
            flag=false;
            
        }
        for(int i=a;i<=b;i++){
            if(cal(i)>max)max=cal(i);
        }
        if(flag)
        cout<<a<<" "<<b<<" "<<max<<endl;
        else cout<<b<<" "<<a<<" "<<max<<endl;
    }
    //system("pause");
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator