| ||||||||||
| 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 | |||||||||
Help ! please lokk look ,thank than you!!!!#include <queue>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct point
{
int x,y;
point(int xx,int yy) : x(xx),y(yy){}
};
bool use[100001];
int main()
{
int A,B;
while( scanf("%d%d",&A,&B)!=EOF )
{
memset(use,0,sizeof(use));
queue <point> Q;
Q.push(point(A,0));
use[A]++;
while( !Q.empty() )
{
point temp1 = Q.front();
Q.pop();
point temp2 = temp1;
temp2.x = temp1.x-1;
if( temp2.x == B )
{
printf("%d\n",++temp2.y);
break;
}
if( temp2.x >= 0 && !use[temp2.x] )
{
temp2.y++;
use[temp2.x]++;
Q.push(temp2);
}
point temp3 = temp1;
temp3.x = temp1.x+1;
if( temp3.x == B )
{
printf("%d\n",++temp3.y);
break;
}
if( temp3.x <100000 && !use[temp3.x] )
{
temp3.y++;
use[temp3.x]++;
Q.push(temp3);
}
point temp4 = temp1;
temp4.x = temp1.x*2;
if( temp4.x == B )
{
printf("%d\n",++temp4.y);
break;
}
if( temp4.x <100000 && !use[temp4.x] )
{
temp4.y++;
use[temp4.x]++;
Q.push(temp4);
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator