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

为什么runtime error啊?

Posted by 00948176 at 2010-04-09 18:02:55 on Problem 3278
#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:
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