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

3278 已解决

Posted by zsc08_hyq at 2009-11-22 13:13:32 on Problem 3278
#include<iostream>
using namespace std;
struct xt
{
    int N,t;
}a[100001];
int main()
{
    int K,i,j,k1,used[100001];
    while(scanf("%d%d",&a[0].N,&K)!=EOF)
    {
        if(a[0].N==K) printf("0\n");
        else
        {
            memset(used,0,sizeof(used));
            i=0;
            j=1;
            while(i<j)
            {
                k1=a[i].N+1;
                if(k1==K) break;
                if(k1<100001&&!used[k1])
                {
                    used[k1]=1;
                    a[j].N=k1;
                    a[j++].t=a[i].t+1;
                }    
                k1=a[i].N-1;
                if(k1==K) break;
                if(k1>=0&&!used[k1])
                {
                    used[k1]=1;
                    a[j].N=k1;
                    a[j++].t=a[i].t+1;
                }
                k1=2*a[i].N;
                if(k1==K) break;
                if(k1<100001&&!used[k1])
                {
                    used[k1]=1;
                    a[j].N=k1;
                    a[j++].t=a[i].t+1;
                }
                i++;
            }
            printf("%d\n",a[i].t+1);
        }
    }
    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