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

那位高手帮我看看为什么总是RE,谢谢~~~~~~~~~~~~~~~~

Posted by 20071121141 at 2009-08-03 20:02:32 on Problem 3278
#include<iostream>
#include<memory.h>
using namespace std;
int dir[3]={-1,1,2};
struct STEP{
  int x,t;
}step[2000000];
int visted[2000000];
int main()
{
   int n,m;
   int xx,q,head,tail;
   while(cin>>n>>m)
   {
      if(n>=m)
      {
         cout<<n-m<<endl;
         continue;        
      }
      xx=0,q=0;
      head=0,tail=1;
      memset(step,0,sizeof(step));
      step[head].x=n;
      step[head].t=0;
      memset(visted,0,sizeof(visted));
      while(head<tail)
      {
         for(int i=0;i<3;i++)
         {
            if(i<2)
            xx=step[head].x+dir[i];
            else if(i==2)
            xx=step[head].x*dir[i];
           if(xx>=0)
           { 
            if(xx==m)
            {
               q=1;
               break;
            }
            else if(xx!=m&&visted[xx]==0)
            {
               visted[xx]=1;
               step[tail].x=xx;
               step[tail].t=step[head].t+1;
               tail++; 
            }
           }      
         } 
         head++;
         if(q==1)
         break;
                       
      } 
      cout<<step[head].t+1<<endl;               
   }  
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