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

Help ! please lokk look ,thank than you!!!!

Posted by 20091101579 at 2011-04-11 15:42:22 on Problem 3278
#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:
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