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 |
为什么runtime error啊?#include<iostream> using namespace std; int t[1000000],p[1000000],tmp1=0,tmp2=0,m,p1,p2;//m记录最少时间,p1为农夫所在地,p2为羊所在地 void bfs()//tmp1 记录父节点首个,tmp2记录最后一个 { int i,j; j=tmp2+1;//用于产生子节点 for(i=tmp1;i<=tmp2;i++)//父节点生成子节点 { if(p[i]==p2) {m=t[i];return;} else if(p[i]>p2) { p[j]=p[i]-1; t[j]=t[i]+1; j++; } else{ p[j]=p[i]-1; t[j]=t[i]+1; j++; p[j]=p[i]+1; t[j]=t[i]+1; j++; p[j]=p[i]*2; t[j]=t[i]+1; j++; } } tmp1=tmp2+1; tmp2=j-1; bfs(); } int main() { scanf("%d%d",&p1,&p2); if(p1==p2) printf("0\n"); if(p1>p2) printf("%d\n",p1-p2); else{ p[0]=p1; t[0]=0; bfs(); printf("%d\n",m); } //cin.get(); //cin.get(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator