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 18706657485 at 2011-05-12 15:22:46 on Problem 3278
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int m,n;
int queue[210000];
int visit[210000];
int bfs();
main()
{
    //freopen("in3278.txt","r",stdin);
   while(cin>>m>>n)
    printf("%d\n",bfs());
    return 0;
}
int bfs()
{
    int head=0,end=0,q=0;
    memset(visit,0,sizeof(visit));
    queue[end]=m;
    visit[m]=1;
    end=end+1;
    while(head<end)
    {
        int q=queue[head++];
        //cout<<q<<endl;
        if(q==n)
        return visit[q]-1;
        else
        {
                //cout<<"########\n";
                if((q+1)>=0&&(q+1)<=n&&visit[q+1]==0){queue[end++]=q+1;visit[q+1]=visit[q]+1;}
                if((q-1)>=0&&(q-1)<=n&&visit[q-1]==0){queue[end++]=q-1;visit[q-1]=visit[q]+1;}
                 if((q*2)>=0&&(q*2)<=n&&visit[2*q]==0){queue[end++]=q*2;visit[q*2]=visit[q]+1;}
                //cout<<"########\n";
        }
    }
    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