| ||||||||||
| 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 | |||||||||
请各位神牛帮我看下为什么一直越界。。。郁闷死了#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator