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 |
我想知道为什么G++能AC,改用C++却WA了!!!很无语= =#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<vector> #include<queue> #define N 100010 #define INF 2>>30 using namespace std; int d[N],b[N]; int n,k; queue<int>q; int BFS() { int i,t,h,flag; q.push(n); b[n]=0; flag=0; while(!q.empty()) { h=q.front(); q.pop(); for(i=0;i<3;i++) { if(i==0) t=h-1; if(i==1) t=h+1; if(i==2) t=h*2; if(t<0||t>N) continue; if(d[t]==INF) { d[t]=d[h]+1; q.push(t); } if(t==k) { flag=1; break; } } if(flag) break; } return d[k]; } int main() { while(~scanf("%d%d",&n,&k)) { fill(d,d+N,INF); int hh=BFS(); if(n>=k) printf("%d\n",n-k); else printf("%d\n",hh); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator