| ||||||||||
| 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 | |||||||||
我靠,我在这儿提交了10多次,最后结果是G++不能通过,用C++通过了,我在这儿找了半天地错误。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator