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 alpc_mjh at 2014-02-21 15:53:43 on Problem 3278
#include<iostream>
using namespace std;
#include<string.h>
int a[1000000];
int n;
int count=0;
void BFS(){

 for(int  j=1;j<100;j++){
    count++;
   for(int i=1;i<=10*n;i++){
      if (a[i]==j){
         if (a[i-1]==0)
         a[i-1]=j+1;
         if (a[i+1]==0)
         a[i+1]=j+1;
         if (a[2*i]==0)
         a[2*i]=j+1;
      }
      if (a[n]!=0){
         cout<<a[n]-1;
         break;
      }

   }

   if(a[n]!=0){

      break;
   }


 }
}
int main(){
    int m;
    memset(a,0,sizeof(a));
    cin>>m>>n;
    a[m]=1;
    if (m>=n){
      cout<<m-n;
    }else{
    BFS();
    }


    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