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

我靠,我在这儿提交了10多次,最后结果是G++不能通过,用C++通过了,我在这儿找了半天地错误。

Posted by when at 2016-12-31 20:11:19 on Problem 3278
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

const int N=100000+10;
int a[N];

int BFS(int s,int e){
    memset(a,-1,sizeof(a));

    queue<int> q;
    q.push(s);
    a[s]=0;
    
    while(!q.empty()){
        int tmp=q.front();
        q.pop();
        if(tmp==e)
            return a[tmp];
        if(tmp-1>=0&&a[tmp-1]==-1){
            a[tmp-1]=a[tmp]+1;
            q.push(tmp-1);
        }
        if(tmp+1<=e&&a[tmp+1]==-1){
            a[tmp+1]=a[tmp]+1;
            q.push(tmp+1);
        }
        if(tmp*2<N&&a[tmp*2]==-1){
            a[tmp*2]=a[tmp]+1;
            q.push(2*tmp);
        }
    }
}

int main(){
    int s,e;
    cin>>s>>e;
    cout<<BFS(s,e)<<endl;
}




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