| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
高手帮忙看下哪错了#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator