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

请各位神牛帮我看下为什么一直越界。。。郁闷死了

Posted by forgotaboutdre at 2010-12-30 20:37:17 on Problem 3278
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
#define MAX 999999
bool mark[MAX];
int start,end;
struct queue{
       int x;
       int step;
       }q[200000];



int bfs()
{
    int head=0,tail=0;
    q[head].x=start;
    q[head].step=0;
    mark[start]=1;
    while(head<=tail)
  {
     queue temp=q[head];
      if(temp.x==end)
	  {
        return 0;
		break;
	  }
	  else
	{
      queue newq;
      newq.x=2*temp.x;
       if(mark[newq.x]!=1&&newq.x<=200000)
      {
          mark[newq.x]=1;
          newq.step=temp.step+1;
          q[++tail]=newq;
		  if(newq.x==end)
		  {
			  return newq.step;
		      break;
		  }
      newq.x=temp.x-1;
      if(mark[newq.x]!=1&&newq.x<=200000)
      {
          mark[newq.x]=1;
          newq.step=temp.step+1;
          q[++tail]=newq;
		  if(newq.x==end)
		  {
			  return newq.step;
		      break;
		  }

      }
      newq.x=temp.x+1;
       if(mark[newq.x]!=1&&newq.x<=200000)
      {
          mark[newq.x]=1;
          newq.step=temp.step+1;
          q[++tail]=newq;
		  if(newq.x==end)
		  {
			  return newq.step;
		      break;
		  }
      }
      
      }
	}
      head++;
  }
}

int main()
{ memset(mark,0,sizeof(mark));
scanf("%d%d",&start,&end);
printf("%d\n",bfs());
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