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

谁能帮我看看为什么一直WA呢

Posted by karying at 2010-11-19 18:43:00 on Problem 3278
#include<iostream>
#include<string.h>
using namespace std;
int a[200010];
int b[200010];
int p[200010];
int main()
{
    int n,k;
    int i,j;
    while(cin>>n>>k)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(p,0,sizeof(p));
        a[0]=n;
        p[n+1]=1;
        b[0]=0;
        i=0;
        j=1;
        while(i<j)
        {
            if(a[i]==k) break;

            if((a[i]-1)>=0&&!p[a[i]])
            {
            a[j]=(a[i]-1);
            b[j]=b[i]+1;
            ++j;
            }
            if((a[i]+1)<=100000&&!p[a[i]+2])
            {
            a[j]=(a[i]+1);
            b[j]=b[i]+1;
            ++j;
            }
            if((2*a[i])<=100000&&!p[a[i]*2+1])
            {
            a[j]=2*a[i];
            b[j]=b[i]+1;
            ++j;
            }
            
            i++;
        }
        cout<<b[i]<<endl;


    }



    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