| ||||||||||
| 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 | |||||||||
那位高手帮我看看为什么总是RE,谢谢~~~~~~~~~~~~~~~~#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator